@@ -22,8 +22,8 @@ type shellCmd struct {
22
22
func (cmd * shellCmd ) Spec () cli.CommandSpec {
23
23
return cli.CommandSpec {
24
24
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\n If no command is specified, the default shell is opened. " ,
27
27
RawArgs : true ,
28
28
}
29
29
}
@@ -36,36 +36,46 @@ func enableTerminal(fd int) {
36
36
}
37
37
38
38
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
56
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
56
+ }
57
57
}
58
58
59
59
func (cmd * shellCmd ) Run (fl * pflag.FlagSet ) {
60
- if len (fl .Args ()) < 2 {
60
+ if len (fl .Args ()) < 1 {
61
61
exitUsage (fl )
62
62
}
63
63
var (
64
64
envName = fl .Arg (0 )
65
65
command = fl .Arg (1 )
66
- args = fl .Args ()[2 :]
67
66
)
68
67
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
+
69
79
var (
70
80
entClient = requireAuth ()
71
81
env = findEnv (entClient , envName )
0 commit comments