diff --git a/README.md b/README.md index f2832fe..cb45a48 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,6 @@ Option | Description `-s` | select initial container sort field `-scale-cpu` | show cpu as % of system total `-v` | output version information and exit -`-shell` | exec shell to use (default: sh) ### Keybindings diff --git a/config/param.go b/config/param.go index dc334f5..281cc6c 100644 --- a/config/param.go +++ b/config/param.go @@ -12,11 +12,6 @@ var defaultParams = []*Param{ Val: "state", Label: "Container Sort Field", }, - &Param{ - Key: "shell", - Val: "sh", - Label: "Shell", - }, &Param{ Key: "columns", Val: "status,name,id,cpu,mem,net,io,pids", diff --git a/main.go b/main.go index ea1ea7c..71b7dde 100644 --- a/main.go +++ b/main.go @@ -46,7 +46,6 @@ func main() { invertFlag = flag.Bool("i", false, "invert default colors") scaleCpu = flag.Bool("scale-cpu", false, "show cpu as % of system total") connectorFlag = flag.String("connector", "docker", "container connector to use") - defaultShell = flag.String("shell", "sh", "exec shell to use") ) flag.Parse() @@ -91,10 +90,6 @@ func main() { config.Toggle("scaleCpu") } - if *defaultShell != "" { - config.Update("shell", *defaultShell) - } - // init ui if *invertFlag { InvertColorMap() diff --git a/menus.go b/menus.go index c3ca2af..4e0cd6a 100644 --- a/menus.go +++ b/menus.go @@ -358,10 +358,17 @@ func ExecShell() MenuFn { ui.DefaultEvtStream.ResetHandlers() defer ui.DefaultEvtStream.ResetHandlers() - - shell := config.Get("shell") - if err := c.Exec([]string{shell.Val, "-c", "printf '\\e[0m\\e[?25h' && clear && " + shell.Val}); err != nil { - log.Fatal(err) + // Detect and execute default shell in container. + // Execute Ash shell command: /bin/sh -c + // Reset colors: printf '\e[0m\e[?25h' + // Clear screen + // Run default shell for the user. It's configured in /etc/passwd and looks like root:x:0:0:root:/root:/bin/bash: + // 1. Get current user id: id -un + // 2. Find user's line in /etc/passwd by grep + // 3. Extract default user's shell by cutting seven's column separated by : + // 4. Execute the shell path with eval + if err := c.Exec([]string{"/bin/sh", "-c", "printf '\\e[0m\\e[?25h' && clear && eval `grep ^$(id -un): /etc/passwd | cut -d : -f 7-`"}); err != nil { + log.StatusErr(err) } return nil