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

Commit f92b161

Browse files
committed
Use default shell if no command specified
1 parent 1963400 commit f92b161

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

cmd/coder/shell.go

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ type shellCmd struct {
2222
func (cmd *shellCmd) Spec() cli.CommandSpec {
2323
return cli.CommandSpec{
2424
Name: "sh",
25-
Usage: "<env name> <command [command args...]>",
26-
Desc: "executes a remote command on the environment",
25+
Usage: "<env name> [<command [args...]>]",
26+
Desc: "executes a remote command on the environment\nIf no command is specified, the default shell is opened.",
2727
RawArgs: true,
2828
}
2929
}
@@ -36,36 +36,46 @@ func enableTerminal(fd int) {
3636
}
3737

3838
func (cmd *shellCmd) sendResizeEvents(termfd int, client *wush.Client) {
39-
sigs := make(chan os.Signal, 16)
40-
signal.Notify(sigs, unix.SIGWINCH)
41-
42-
for {
43-
width, height, err := terminal.GetSize(termfd)
44-
if err != nil {
45-
flog.Error("get term size: %v", err)
46-
return
47-
}
48-
49-
err = client.Resize(width, height)
50-
if err != nil {
51-
flog.Error("get term size: %v", err)
52-
return
53-
}
54-
// Do this last so the first resize is sent.
55-
<-sigs
39+
sigs := make(chan os.Signal, 16)
40+
signal.Notify(sigs, unix.SIGWINCH)
41+
42+
for {
43+
width, height, err := terminal.GetSize(termfd)
44+
if err != nil {
45+
flog.Error("get term size: %v", err)
46+
return
5647
}
48+
49+
err = client.Resize(width, height)
50+
if err != nil {
51+
flog.Error("get term size: %v", err)
52+
return
53+
}
54+
// Do this last so the first resize is sent.
55+
<-sigs
56+
}
5757
}
5858

5959
func (cmd *shellCmd) Run(fl *pflag.FlagSet) {
60-
if len(fl.Args()) < 2 {
60+
if len(fl.Args()) < 1 {
6161
exitUsage(fl)
6262
}
6363
var (
6464
envName = fl.Arg(0)
6565
command = fl.Arg(1)
66-
args = fl.Args()[2:]
6766
)
6867

68+
var args []string
69+
if command != "" {
70+
args = fl.Args()[2:]
71+
}
72+
73+
// Bring user into shell if no command is specified.
74+
if command == "" {
75+
command = "sh"
76+
args = []string{"-c", "exec $(getent passwd $(whoami) | awk -F: '{ print $7 }')"}
77+
}
78+
6979
var (
7080
entClient = requireAuth()
7181
env = findEnv(entClient, envName)

0 commit comments

Comments
 (0)