mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-22 15:11:02 +00:00
add new config option to add handle preferred shells to execute on the container
This commit is contained in:
parent
6cd2e5625d
commit
0f8786995e
2 changed files with 28 additions and 3 deletions
|
|
@ -216,6 +216,9 @@ type CommandTemplatesConfig struct {
|
|||
|
||||
// ServiceTop is the command for viewing the processes under a given service
|
||||
ServiceTop string `yaml:"serviceTop,omitempty"`
|
||||
|
||||
// List of shells that, in given order, will be tried when attaching to a container.
|
||||
PreferredExecShells []string `yaml:"preferedExecShell,omitempty"`
|
||||
}
|
||||
|
||||
// OSConfig contains config on the level of the os
|
||||
|
|
@ -398,6 +401,7 @@ func GetDefaultConfig() UserConfig {
|
|||
DockerComposeConfig: "{{ .DockerCompose }} config",
|
||||
CheckDockerComposeConfig: "{{ .DockerCompose }} config --quiet",
|
||||
ServiceTop: "{{ .DockerCompose }} top {{ .Service.Name }}",
|
||||
PreferredExecShells: []string{},
|
||||
},
|
||||
CustomCommands: CustomCommands{
|
||||
Containers: []CustomCommand{},
|
||||
|
|
|
|||
|
|
@ -449,11 +449,32 @@ func (gui *Gui) containerExecShell(container *commands.Container) error {
|
|||
commandObject := gui.DockerCommand.NewCommandObject(commands.CommandObject{
|
||||
Container: container,
|
||||
})
|
||||
var command string
|
||||
shell := ""
|
||||
|
||||
// TODO: use SDK
|
||||
resolvedCommand := utils.ApplyTemplate("docker exec -it {{ .Container.ID }} /bin/sh -c 'eval $(grep ^$(id -un): /etc/passwd | cut -d : -f 7-)'", commandObject)
|
||||
preferredExecShells := gui.Config.UserConfig.CommandTemplates.PreferredExecShells
|
||||
if len(preferredExecShells) > 0 {
|
||||
for _, preferredExecShell := range preferredExecShells {
|
||||
command := utils.ApplyTemplate(fmt.Sprintf("docker exec {{ .Container.ID }} which %s", preferredExecShell), commandObject)
|
||||
|
||||
err := gui.runCommandSilently(gui.OSCommand.ExecutableFromString(command))
|
||||
if err == nil {
|
||||
shell = preferredExecShell
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Use SDK
|
||||
// Use default implementation in case we cannot fulfill user's preference
|
||||
if shell == "" {
|
||||
command = utils.ApplyTemplate("docker exec -it {{ .Container.ID }} /bin/sh -c 'eval $(grep ^$(id -un): /etc/passwd | cut -d : -f 7-)'", commandObject)
|
||||
} else {
|
||||
command = utils.ApplyTemplate(fmt.Sprintf("docker exec -it {{ .Container.ID }} %s", shell), commandObject)
|
||||
}
|
||||
|
||||
cmd := gui.OSCommand.ExecutableFromString(command)
|
||||
// attach and return the subprocess error
|
||||
cmd := gui.OSCommand.ExecutableFromString(resolvedCommand)
|
||||
return gui.runSubprocess(cmd)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue