diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index 20a4d8cd..32255602 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -51,6 +51,8 @@ type CommandObject struct { DockerCompose string Service *Service Container *Container + Image *Image + Volume *Volume } // NewCommandObject takes a command object and returns a default command object with the passed command object merged in diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 6ed1e3af..79ed97d0 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -258,6 +258,12 @@ type CustomCommands struct { // Services contains the custom commands for services Services []CustomCommand `yaml:"services,omitempty"` + + // Services contains the custom commands for services + Images []CustomCommand `yaml:"images,omitempty"` + + // Services contains the custom commands for services + Volumes []CustomCommand `yaml:"volumes,omitempty"` } // CustomCommand is a template for a command we want to run against a service or @@ -335,6 +341,8 @@ func GetDefaultConfig() UserConfig { }, }, Services: []CustomCommand{}, + Images: []CustomCommand{}, + Volumes: []CustomCommand{}, }, OS: GetPlatformDefaultConfig(), Update: UpdateConfig{ diff --git a/pkg/gui/images_panel.go b/pkg/gui/images_panel.go index 83a66bb1..1e2c2b74 100644 --- a/pkg/gui/images_panel.go +++ b/pkg/gui/images_panel.go @@ -259,3 +259,19 @@ func (gui *Gui) handlePruneImages(g *gocui.Gui, v *gocui.View) error { }) }, nil) } + +func (gui *Gui) handleImagesCustomCommand(g *gocui.Gui, v *gocui.View) error { + image, err := gui.getSelectedImage(g) + if err != nil { + return nil + } + + commandObject := gui.DockerCommand.NewCommandObject( + commands.CommandObject{ + Image: image, + }) + + customCommands := gui.Config.UserConfig.CustomCommands.Images + + return gui.createCustomCommandMenu(customCommands, commandObject) +} diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index ccedcaa1..898a9ba9 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -337,6 +337,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Handler: gui.handleImagesNextContext, Description: gui.Tr.NextContext, }, + { + ViewName: "images", + Key: 'c', + Modifier: gocui.ModNone, + Handler: gui.handleImagesCustomCommand, + Description: gui.Tr.RunCustomCommand, + }, { ViewName: "images", Key: 'd', @@ -365,6 +372,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Handler: gui.handleVolumesNextContext, Description: gui.Tr.NextContext, }, + { + ViewName: "volumes", + Key: 'c', + Modifier: gocui.ModNone, + Handler: gui.handleVolumesCustomCommand, + Description: gui.Tr.RunCustomCommand, + }, { ViewName: "volumes", Key: 'd', diff --git a/pkg/gui/volumes_panel.go b/pkg/gui/volumes_panel.go index 2fb4291e..1c2a4878 100644 --- a/pkg/gui/volumes_panel.go +++ b/pkg/gui/volumes_panel.go @@ -250,3 +250,19 @@ func (gui *Gui) handlePruneVolumes(g *gocui.Gui, v *gocui.View) error { }) }, nil) } + +func (gui *Gui) handleVolumesCustomCommand(g *gocui.Gui, v *gocui.View) error { + volume, err := gui.getSelectedVolume() + if err != nil { + return nil + } + + commandObject := gui.DockerCommand.NewCommandObject( + commands.CommandObject{ + Volume: volume, + }) + + customCommands := gui.Config.UserConfig.CustomCommands.Volumes + + return gui.createCustomCommandMenu(customCommands, commandObject) +}