Skip to content

Commit

Permalink
support setting description in custom command
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Sep 27, 2020
1 parent 1b39c82 commit de48226
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/Custom_Command_Keybindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ customCommands:
- key: 'a'
command: "git {{if .SelectedFile.HasUnstagedChanges}} add {{else}} reset {{end}} {{.SelectedFile.Name}}"
context: 'files'
description: 'toggle file staged'
- key: 'C'
command: "git commit"
context: 'global'
Expand Down Expand Up @@ -53,6 +54,7 @@ For a given custom command, here are the allowed fields:
| subprocess | whether you want the command to run in a subprocess (necessary if you want to view the output of the command or provide user input) | no |
| prompts | a list of prompts that will request user input before running the final command | no |
| loadingText | text to display while waiting for command to finish | no |
| description | text to display in the keybindings menu that appears when you press 'x' | no |

### Contexts

Expand Down
8 changes: 7 additions & 1 deletion pkg/gui/custom_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ type CustomCommand struct {
Subprocess bool `yaml:"subprocess"`
Prompts []CustomCommandPrompt `yaml:"prompts"`
LoadingText string `yaml:"loadingText"`
Description string `yaml:"description"`
}

func (gui *Gui) GetCustomCommandKeybindings() []*Binding {
Expand Down Expand Up @@ -230,13 +231,18 @@ func (gui *Gui) GetCustomCommandKeybindings() []*Binding {
contexts = []string{customCommand.Context}
}

description := customCommand.Description
if description == "" {
description = customCommand.Command
}

bindings = append(bindings, &Binding{
ViewName: viewName,
Contexts: contexts,
Key: gui.getKey(customCommand.Key),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleCustomCommandKeybinding(customCommand)),
Description: customCommand.Command,
Description: description,
})
}

Expand Down

0 comments on commit de48226

Please sign in to comment.