mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
Ability to change Shell
This commit is contained in:
parent
967a87a65f
commit
a26fc9169c
@ -70,6 +70,7 @@ 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 | specify shell (default: sh)
|
||||||
|
|
||||||
### Keybindings
|
### Keybindings
|
||||||
|
|
||||||
@ -84,6 +85,7 @@ s | Select container sort field
|
|||||||
r | Reverse container sort order
|
r | Reverse container sort order
|
||||||
o | Open single view
|
o | Open single view
|
||||||
l | View container logs (`t` to toggle timestamp when open)
|
l | View container logs (`t` to toggle timestamp when open)
|
||||||
|
e | Exec Shell
|
||||||
S | Save current configuration to file
|
S | Save current configuration to file
|
||||||
q | Quit ctop
|
q | Quit ctop
|
||||||
|
|
||||||
|
@ -12,6 +12,11 @@ var params = []*Param{
|
|||||||
Val: "state",
|
Val: "state",
|
||||||
Label: "Container Sort Field",
|
Label: "Container Sort Field",
|
||||||
},
|
},
|
||||||
|
&Param{
|
||||||
|
Key: "shell",
|
||||||
|
Val: "sh",
|
||||||
|
Label: "Shell",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
type Param struct {
|
type Param struct {
|
||||||
|
2
grid.go
2
grid.go
@ -117,7 +117,7 @@ func Display() bool {
|
|||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
ui.Handle("/sys/kbd/e", func(ui.Event) {
|
ui.Handle("/sys/kbd/e", func(ui.Event) {
|
||||||
menu = ExecSh
|
menu = ExecShell
|
||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
ui.Handle("/sys/kbd/o", func(ui.Event) {
|
ui.Handle("/sys/kbd/o", func(ui.Event) {
|
||||||
|
5
main.go
5
main.go
@ -45,6 +45,7 @@ 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", "", "default shell")
|
||||||
)
|
)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@ -87,6 +88,10 @@ func main() {
|
|||||||
config.Toggle("scaleCpu")
|
config.Toggle("scaleCpu")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *defaultShell != "" {
|
||||||
|
config.Update("shell", *defaultShell)
|
||||||
|
}
|
||||||
|
|
||||||
// init ui
|
// init ui
|
||||||
if *invertFlag {
|
if *invertFlag {
|
||||||
InvertColorMap()
|
InvertColorMap()
|
||||||
|
15
menus.go
15
menus.go
@ -25,7 +25,7 @@ var helpDialog = []menu.Item{
|
|||||||
{"[r] - reverse container sort order", ""},
|
{"[r] - reverse container sort order", ""},
|
||||||
{"[o] - open single view", ""},
|
{"[o] - open single view", ""},
|
||||||
{"[l] - view container logs ([t] to toggle timestamp when open)", ""},
|
{"[l] - view container logs ([t] to toggle timestamp when open)", ""},
|
||||||
{"[e] - exec sh", ""},
|
{"[e] - exec shell", ""},
|
||||||
{"[S] - save current configuration to file", ""},
|
{"[S] - save current configuration to file", ""},
|
||||||
{"[q] - exit ctop", ""},
|
{"[q] - exit ctop", ""},
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ func ContainerMenu() MenuFn {
|
|||||||
items = append(items, menu.Item{Val: "stop", Label: "stop"})
|
items = append(items, menu.Item{Val: "stop", Label: "stop"})
|
||||||
items = append(items, menu.Item{Val: "pause", Label: "pause"})
|
items = append(items, menu.Item{Val: "pause", Label: "pause"})
|
||||||
items = append(items, menu.Item{Val: "restart", Label: "restart"})
|
items = append(items, menu.Item{Val: "restart", Label: "restart"})
|
||||||
items = append(items, menu.Item{Val: "exec sh", Label: "exec sh"})
|
items = append(items, menu.Item{Val: "exec shell", Label: "exec shell"})
|
||||||
}
|
}
|
||||||
if c.Meta["state"] == "exited" || c.Meta["state"] == "created" {
|
if c.Meta["state"] == "exited" || c.Meta["state"] == "created" {
|
||||||
items = append(items, menu.Item{Val: "start", Label: "start"})
|
items = append(items, menu.Item{Val: "start", Label: "start"})
|
||||||
@ -158,8 +158,8 @@ func ContainerMenu() MenuFn {
|
|||||||
nextMenu = SingleView
|
nextMenu = SingleView
|
||||||
case "logs":
|
case "logs":
|
||||||
nextMenu = LogMenu
|
nextMenu = LogMenu
|
||||||
case "exec sh":
|
case "exec shell":
|
||||||
nextMenu = ExecSh
|
nextMenu = ExecShell
|
||||||
case "start":
|
case "start":
|
||||||
nextMenu = Confirm(confirmTxt("start", c.GetMeta("name")), c.Start)
|
nextMenu = Confirm(confirmTxt("start", c.GetMeta("name")), c.Start)
|
||||||
case "stop":
|
case "stop":
|
||||||
@ -211,7 +211,7 @@ func LogMenu() MenuFn {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExecSh() MenuFn {
|
func ExecShell() MenuFn {
|
||||||
c := cursor.Selected()
|
c := cursor.Selected()
|
||||||
|
|
||||||
if c == nil {
|
if c == nil {
|
||||||
@ -223,7 +223,10 @@ func ExecSh() MenuFn {
|
|||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
defer ui.Loop()
|
defer ui.Loop()
|
||||||
|
|
||||||
c.Exec([]string{"sh", "-c", "echo '\033[0m' && clear && sh"})
|
shell := config.Get("shell")
|
||||||
|
if err := c.Exec([]string{shell.Val, "-c", "echo '\033[0m' && clear && " + shell.Val}); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user