diff --git a/docs/Config.md b/docs/Config.md index c67562f5..5f35dc72 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -47,7 +47,7 @@ customCommands: containers: - name: bash attach: true - command: docker exec -it {{ .Container.ID }} /bin/sh + command: "docker exec -it {{ .Container.ID }} /bin/sh -c 'eval $(grep ^$(id -un): /etc/passwd | cut -d : -f 7-)'" serviceNames: [] oS: openCommand: open {{filename}} diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index edf4591b..8c8fa8a9 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -344,7 +344,7 @@ func GetDefaultConfig() UserConfig { Containers: []CustomCommand{ { Name: "bash", - Command: "docker exec -it {{ .Container.ID }} /bin/sh", + Command: "docker exec -it {{ .Container.ID }} /bin/sh -c 'eval $(grep ^$(id -un): /etc/passwd | cut -d : -f 7-)'", Attach: true, }, }, diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index f60561b1..25fb6770 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -509,6 +509,21 @@ func (gui *Gui) handleContainerViewLogs(g *gocui.Gui, v *gocui.View) error { return gui.Errors.ErrSubProcess } +func (gui *Gui) handleContainersExecShell(g *gocui.Gui, v *gocui.View) error { + container, err := gui.getSelectedContainer() + if err != nil { + return nil + } + commandObject := gui.DockerCommand.NewCommandObject(commands.CommandObject{ + Container: container, + }) + resolvedCommand := utils.ApplyTemplate("docker exec -it {{ .Container.ID }} /bin/sh -c 'eval $(grep ^$(id -un): /etc/passwd | cut -d : -f 7-)'", commandObject) + // attach and return the subprocess error + cmd := gui.OSCommand.ExecutableFromString(resolvedCommand) + gui.SubProcess = cmd + return gui.Errors.ErrSubProcess +} + func (gui *Gui) handleContainersCustomCommand(g *gocui.Gui, v *gocui.View) error { container, err := gui.getSelectedContainer() if err != nil { diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index d421cb15..d7784a41 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -248,6 +248,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Handler: gui.handleContainerViewLogs, Description: gui.Tr.ViewLogs, }, + { + ViewName: "containers", + Key: 'E', + Modifier: gocui.ModNone, + Handler: gui.handleContainersExecShell, + Description: gui.Tr.ExecShell, + }, { ViewName: "containers", Key: 'c', diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index fc7c167d..81aaf0c9 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -80,6 +80,7 @@ type TranslationSet struct { StopAllContainers string RemoveAllContainers string ViewRestartOptions string + ExecShell string RunCustomCommand string ViewBulkCommands string OpenInBrowser string @@ -149,6 +150,7 @@ func englishSet() TranslationSet { StopAllContainers: "stop all containers", RemoveAllContainers: "remove all containers (forced)", ViewRestartOptions: "view restart options", + ExecShell: "exec shell", RunCustomCommand: "run predefined custom command", ViewBulkCommands: "view bulk commands", OpenInBrowser: "open in browser (first port is http)",