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
commit 2792e72d18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 15 deletions

View File

@ -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

View File

@ -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",

View File

@ -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()

View File

@ -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