summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-05-19 20:43:22 +0200
committerStefan Haller <stefan@haller-berlin.de>2024-05-20 21:02:49 +0200
commit22a38c9f5026c4b23d8288ef194235dfe52b03e3 (patch)
tree40ac91f412ff14861c1312ac8d20204af212508d
parent6343fb57d605a488f4d3ff6cd1f13341307b6159 (diff)
Add property outputTitle to CustomCommand
It can optionally be used to set the title of the panel that shows the output of a command (when showOutput is true). If left unset, the command string is used as the title.
-rw-r--r--docs/Custom_Command_Keybindings.md1
-rw-r--r--pkg/config/user_config.go2
-rw-r--r--pkg/gui/services/custom_commands/handler_creator.go10
-rw-r--r--pkg/integration/tests/custom_commands/show_output_in_panel.go57
-rw-r--r--pkg/integration/tests/test_list.go1
-rw-r--r--schema/config.json4
6 files changed, 74 insertions, 1 deletions
diff --git a/docs/Custom_Command_Keybindings.md b/docs/Custom_Command_Keybindings.md
index 426d6f8f6..1053f9e45 100644
--- a/docs/Custom_Command_Keybindings.md
+++ b/docs/Custom_Command_Keybindings.md
@@ -59,6 +59,7 @@ For a given custom command, here are the allowed fields:
| description | Label for the custom command when displayed in the keybindings menu | no |
| stream | Whether you want to stream the command's output to the Command Log panel | no |
| showOutput | Whether you want to show the command's output in a popup within Lazygit | no |
+| outputTitle | The title to display in the popup panel if showOutput is true. If left unset, the command will be used as the title. | no |
| after | Actions to take after the command has completed | no |
Here are the options for the `after` key:
diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go
index 2df6e60b8..904b20141 100644
--- a/pkg/config/user_config.go
+++ b/pkg/config/user_config.go
@@ -581,6 +581,8 @@ type CustomCommand struct {
Stream bool `yaml:"stream"`
// If true, show the command's output in a popup within Lazygit
ShowOutput bool `yaml:"showOutput"`
+ // The title to display in the popup panel if showOutput is true. If left unset, the command will be used as the title.
+ OutputTitle string `yaml:"outputTitle"`
// Actions to take after the command has completed
After CustomCommandAfterHook `yaml:"after"`
}
diff --git a/pkg/gui/services/custom_commands/handler_creator.go b/pkg/gui/services/custom_commands/handler_creator.go
index 9a127f362..c1cfe09cb 100644
--- a/pkg/gui/services/custom_commands/handler_creator.go
+++ b/pkg/gui/services/custom_commands/handler_creator.go
@@ -292,7 +292,15 @@ func (self *HandlerCreator) finalHandler(customCommand config.CustomCommand, ses
if strings.TrimSpace(output) == "" {
output = self.c.Tr.EmptyOutput
}
- return self.c.Alert(cmdStr, output)
+
+ title := cmdStr
+ if customCommand.OutputTitle != "" {
+ title, err = resolveTemplate(customCommand.OutputTitle)
+ if err != nil {
+ return err
+ }
+ }
+ return self.c.Alert(title, output)
}
return nil
diff --git a/pkg/integration/tests/custom_commands/show_output_in_panel.go b/pkg/integration/tests/custom_commands/show_output_in_panel.go
new file mode 100644
index 000000000..e98f372e6
--- /dev/null
+++ b/pkg/integration/tests/custom_commands/show_output_in_panel.go
@@ -0,0 +1,57 @@
+package custom_commands
+
+import (
+ "fmt"
+
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var ShowOutputInPanel = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Run a command and show the output in a panel",
+ ExtraCmdArgs: []string{},
+ Skip: false,
+ SetupRepo: func(shell *Shell) {
+ shell.EmptyCommit("my change")
+ },
+ SetupConfig: func(cfg *config.AppConfig) {
+ cfg.UserConfig.CustomCommands = []config.CustomCommand{
+ {
+ Key: "X",
+ Context: "commits",
+ Command: "printf '%s' '{{ .SelectedLocalCommit.Name }}'",
+ ShowOutput: true,
+ },
+ {
+ Key: "Y",
+ Context: "commits",
+ Command: "printf '%s' '{{ .SelectedLocalCommit.Name }}'",
+ ShowOutput: true,
+ OutputTitle: "Subject of commit {{ .SelectedLocalCommit.Hash }}",
+ },
+ }
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Commits().
+ Focus().
+ Lines(
+ Contains("my change").IsSelected(),
+ ).
+ Press("X")
+
+ t.ExpectPopup().Alert().
+ // Uses cmd string as title if no outputTitle is provided
+ Title(Equals("printf '%s' 'my change'")).
+ Content(Equals("my change")).
+ Confirm()
+
+ t.Views().Commits().
+ Press("Y")
+
+ hash := t.Git().GetCommitHash("HEAD")
+ t.ExpectPopup().Alert().
+ // Uses provided outputTitle with template fields resolved
+ Title(Equals(fmt.Sprintf("Subject of commit %s", hash))).
+ Content(Equals("my change"))
+ },
+})
diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go
index e043d4a8a..c65db5abc 100644
--- a/pkg/integration/tests/test_list.go
+++ b/pkg/integration/tests/test_list.go
@@ -113,6 +113,7 @@ var tests = []*components.IntegrationTest{
custom_commands.MenuFromCommandsOutput,
custom_commands.MultiplePrompts,
custom_commands.OmitFromHistory,
+ custom_commands.ShowOutputInPanel,
custom_commands.SuggestionsCommand,
custom_commands.SuggestionsPreset,
demo.AmendOldCommit,
diff --git a/schema/config.json b/schema/config.json
index 9764e2286..626ad1573 100644
--- a/schema/config.json
+++ b/schema/config.json
@@ -924,6 +924,10 @@
"type": "boolean",
"description": "If true, show the command's output in a popup within Lazygit"
},
+ "outputTitle": {
+ "type": "string",
+ "description": "The title to display in the popup panel if showOutput is true. If left unset, the command will be used as the title."
+ },
"after": {
"properties": {
"checkForConflicts": {