summaryrefslogtreecommitdiffstats
path: root/pkg/gui/services
diff options
context:
space:
mode:
authorMichael Mead <mmead.developer@gmail.com>2022-06-24 22:37:10 -0700
committerMichael Mead <mmead.developer@gmail.com>2022-07-04 11:36:13 -0700
commit9d304098bb91336f621fefdef53a645b22dbb9d5 (patch)
tree0cf131bab84d7de474724356f1f858c0c6de4eaf /pkg/gui/services
parent582b1991a47fc53436ee20ac52479cd48004a56d (diff)
feat: add confirm prompt for custom keybindings
- Supports configuring a custom confirmation prompt via `config.yml` for custom keybindings. A new `CustomCommandPrompt.Body` field is used to store the immutable body text of the confirmation popup. - Adds a sample 'confirm' prompt to the example `config.yml`. - Updates the `Prompts` section of the documentation to include 'confirm' prompt type and also describe which fields pertain to it (i.e. `initialValue`). Closes: https://github.com/jesseduffield/lazygit/issues/1858 Signed-off-by: Michael Mead <mmead.developer@gmail.com>
Diffstat (limited to 'pkg/gui/services')
-rw-r--r--pkg/gui/services/custom_commands/handler_creator.go14
-rw-r--r--pkg/gui/services/custom_commands/resolver.go5
2 files changed, 18 insertions, 1 deletions
diff --git a/pkg/gui/services/custom_commands/handler_creator.go b/pkg/gui/services/custom_commands/handler_creator.go
index 446ac95f4..3dd9a0517 100644
--- a/pkg/gui/services/custom_commands/handler_creator.go
+++ b/pkg/gui/services/custom_commands/handler_creator.go
@@ -80,8 +80,12 @@ func (self *HandlerCreator) call(customCommand config.CustomCommand) func() erro
f = func() error {
return self.menuPromptFromCommand(resolvedPrompt, wrappedF)
}
+ case "confirm":
+ f = func() error {
+ return self.confirmPrompt(resolvedPrompt, g)
+ }
default:
- return self.c.ErrorMsg("custom command prompt must have a type of 'input', 'menu' or 'menuFromCommand'")
+ return self.c.ErrorMsg("custom command prompt must have a type of 'input', 'menu', 'menuFromCommand', or 'confirm'")
}
}
@@ -112,6 +116,14 @@ func (self *HandlerCreator) menuPrompt(prompt *config.CustomCommandPrompt, wrapp
return self.c.Menu(types.CreateMenuOptions{Title: prompt.Title, Items: menuItems})
}
+func (self *HandlerCreator) confirmPrompt(prompt *config.CustomCommandPrompt, handleConfirm func() error) error {
+ return self.c.Confirm(types.ConfirmOpts{
+ Title: prompt.Title,
+ Prompt: prompt.Body,
+ HandleConfirm: handleConfirm,
+ })
+}
+
func (self *HandlerCreator) menuPromptFromCommand(prompt *config.CustomCommandPrompt, wrappedF func(string) error) error {
// Run and save output
message, err := self.git.Custom.RunWithOutput(prompt.Command)
diff --git a/pkg/gui/services/custom_commands/resolver.go b/pkg/gui/services/custom_commands/resolver.go
index ee965e5cd..35ebbd9d1 100644
--- a/pkg/gui/services/custom_commands/resolver.go
+++ b/pkg/gui/services/custom_commands/resolver.go
@@ -34,6 +34,11 @@ func (self *Resolver) resolvePrompt(
return nil, err
}
+ result.Body, err = resolveTemplate(prompt.Body)
+ if err != nil {
+ return nil, err
+ }
+
result.Command, err = resolveTemplate(prompt.Command)
if err != nil {
return nil, err