Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 27020b7

Browse files
authored
Merge pull request #75 from cdr/exec-in-shell
Execute exec commands in sh
2 parents c8cec8e + c301cf0 commit 27020b7

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

cmd/coder/shell.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66
"os"
77
"os/signal"
8+
"strings"
89
"time"
910

1011
"github.com/spf13/pflag"
@@ -79,19 +80,16 @@ func (cmd *shellCmd) Run(fl *pflag.FlagSet) {
7980
}
8081
var (
8182
envName = fl.Arg(0)
82-
command = fl.Arg(1)
8383
ctx = context.Background()
8484
)
8585

86-
var args []string
87-
if command != "" {
88-
args = fl.Args()[2:]
89-
}
90-
91-
// Bring user into shell if no command is specified.
92-
if command == "" {
93-
command = "sh"
94-
args = []string{"-c", "exec $(getent passwd $(whoami) | awk -F: '{ print $7 }')"}
86+
command := "sh"
87+
args := []string{"-c"}
88+
if len(fl.Args()) > 1 {
89+
args = append(args, strings.Join(fl.Args()[1:], " "))
90+
} else {
91+
// Bring user into shell if no command is specified.
92+
args = append(args, "exec $(getent passwd $(whoami) | awk -F: '{ print $7 }')")
9593
}
9694

9795
err := runCommand(ctx, envName, command, args)

0 commit comments

Comments
 (0)