Merge pull request #233 from stokito/exec_shell

Exec shell config
This commit is contained in:
bradley
2020-11-20 11:22:59 -05:00
committed by GitHub
4 changed files with 11 additions and 15 deletions

View File

@@ -84,7 +84,6 @@ Option | Description
`-s` | select initial container sort field `-s` | select initial container sort field
`-scale-cpu` | show cpu as % of system total `-scale-cpu` | show cpu as % of system total
`-v` | output version information and exit `-v` | output version information and exit
`-shell` | exec shell to use (default: sh)
### Keybindings ### Keybindings

View File

@@ -12,11 +12,6 @@ var defaultParams = []*Param{
Val: "state", Val: "state",
Label: "Container Sort Field", Label: "Container Sort Field",
}, },
&Param{
Key: "shell",
Val: "sh",
Label: "Shell",
},
&Param{ &Param{
Key: "columns", Key: "columns",
Val: "status,name,id,cpu,mem,net,io,pids", Val: "status,name,id,cpu,mem,net,io,pids",

View File

@@ -46,7 +46,6 @@ func main() {
invertFlag = flag.Bool("i", false, "invert default colors") invertFlag = flag.Bool("i", false, "invert default colors")
scaleCpu = flag.Bool("scale-cpu", false, "show cpu as % of system total") scaleCpu = flag.Bool("scale-cpu", false, "show cpu as % of system total")
connectorFlag = flag.String("connector", "docker", "container connector to use") connectorFlag = flag.String("connector", "docker", "container connector to use")
defaultShell = flag.String("shell", "sh", "exec shell to use")
) )
flag.Parse() flag.Parse()
@@ -91,10 +90,6 @@ func main() {
config.Toggle("scaleCpu") config.Toggle("scaleCpu")
} }
if *defaultShell != "" {
config.Update("shell", *defaultShell)
}
// init ui // init ui
if *invertFlag { if *invertFlag {
InvertColorMap() InvertColorMap()

View File

@@ -358,10 +358,17 @@ func ExecShell() MenuFn {
ui.DefaultEvtStream.ResetHandlers() ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers() defer ui.DefaultEvtStream.ResetHandlers()
// Detect and execute default shell in container.
shell := config.Get("shell") // Execute Ash shell command: /bin/sh -c
if err := c.Exec([]string{shell.Val, "-c", "printf '\\e[0m\\e[?25h' && clear && " + shell.Val}); err != nil { // Reset colors: printf '\e[0m\e[?25h'
log.Fatal(err) // 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 return nil