From 9daa47fb2df8b58a3edc82ed48687205c2bd85e9 Mon Sep 17 00:00:00 2001 From: Elwardi Date: Sat, 17 Jul 2021 19:18:41 +0100 Subject: Add docs for menuFromCommand prompts --- docs/Custom_Command_Keybindings.md | 16 ++++++++++++++++ pkg/gui/custom_commands.go | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/Custom_Command_Keybindings.md b/docs/Custom_Command_Keybindings.md index 5a63e2241..7a9f1bc0d 100644 --- a/docs/Custom_Command_Keybindings.md +++ b/docs/Custom_Command_Keybindings.md @@ -35,6 +35,18 @@ customCommands: command: "git flow {{index .PromptResponses 0}} start {{index .PromptResponses 1}}" context: 'localBranches' loadingText: 'creating branch' + - key : 'r' + description: 'Checkout a remote branch as FETCH_HEAD' + command: "git fetch {{index .PromptResponses 0}} {{index .PromptResponses 1}} && git checkout FETCH_HEAD" + context: 'remotes' + prompts: + - type: 'input' + title: 'Remote:' + initialValue: "{{index .SelectedRemote.Name }}" + - type: 'menuFromCommand' + title: 'Remote branch:' + command: 'git branch -r --list {{index .PromptResponses 0}}/*' + filter: '.*{{index .PromptResponses 0}}/(.*)' ``` Looking at the command assigned to the 'n' key, here's what the result looks like: @@ -85,6 +97,10 @@ The permitted prompt fields are: | title | the title to display in the popup panel | no | | initialValue | (only applicable to 'input' prompts) the initial value to appear in the text box | no | | options | (only applicable to 'menu' prompts) the options to display in the menu | no | +| command | (only applicable to 'menuFromCommand' prompts) the command to run to generate | yes | +| | menu options | | +| filter | (only applicable to 'menuFromCommand' prompts) the regexp to run specify groups | yes | +| | which are going to be kept from the command's output | | The permitted option fields are: | _field_ | _description_ | _required_ | diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go index a17d30dd2..a07bd396b 100644 --- a/pkg/gui/custom_commands.go +++ b/pkg/gui/custom_commands.go @@ -179,11 +179,11 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand var candidates []string reg := regexp.MustCompile(filter) for _,str := range strings.Split(string(message), "\n"){ - cand := str + cand := "" if str != "" { for i := 1; i < (reg.NumSubexp()+1); i++ { - trim := reg.ReplaceAllString(str, "${"+fmt.Sprint(i)+"}") - cand = strings.Trim(cand, trim) + keep := reg.ReplaceAllString(str, "${"+fmt.Sprint(i)+"}") + cand += keep } candidates = append(candidates, cand) } -- cgit v1.2.3