mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-27 12:32:37 +02:00
Consider first match only in menuFromCommand prompt
This commit is contained in:
parent
f1ced5539a
commit
b92ff3ee3f
@ -103,8 +103,8 @@ The permitted prompt fields are:
|
|||||||
| filter | (only applicable to 'menuFromCommand' prompts) the regexp to run specifying | yes |
|
| filter | (only applicable to 'menuFromCommand' prompts) the regexp to run specifying | yes |
|
||||||
| | groups which are going to be kept from the command's output | |
|
| | groups which are going to be kept from the command's output | |
|
||||||
| format | (only applicable to 'menuFromCommand' prompts) how to format matched groups from | yes |
|
| format | (only applicable to 'menuFromCommand' prompts) how to format matched groups from | yes |
|
||||||
| | the filter. You can use named groups, or `{{ .group_GROUPID_MATCHID }}`. | yes |
|
| | the filter. You can use named groups, or `{{ .group_GROUPID }}`. | yes |
|
||||||
| | PS: named groups keep last non-empty match | yes |
|
| | PS: named groups keep first match only | yes |
|
||||||
|
|
||||||
The permitted option fields are:
|
The permitted option fields are:
|
||||||
| _field_ | _description_ | _required_ |
|
| _field_ | _description_ | _required_ |
|
||||||
|
@ -184,31 +184,28 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand
|
|||||||
|
|
||||||
// Need to make a menu out of what the cmd has displayed
|
// Need to make a menu out of what the cmd has displayed
|
||||||
candidates := []string{}
|
candidates := []string{}
|
||||||
|
buff := bytes.NewBuffer(nil)
|
||||||
temp := template.Must(template.New("format").Parse(prompt.Format))
|
temp := template.Must(template.New("format").Parse(prompt.Format))
|
||||||
for _, str := range strings.Split(string(message), "\n") {
|
for _, str := range strings.Split(string(message), "\n") {
|
||||||
if str == "" {
|
if str == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
buff := bytes.NewBuffer(nil)
|
|
||||||
groupNames := reg.SubexpNames()
|
|
||||||
tmplData := map[string]string{}
|
tmplData := map[string]string{}
|
||||||
for matchNum, match := range reg.FindAllStringSubmatch(str, -1) {
|
out := reg.FindAllStringSubmatch(str, -1)
|
||||||
if len(match) > 0 {
|
if len(out) > 0 {
|
||||||
for groupIdx, group := range match {
|
for groupIdx, group := range reg.SubexpNames() {
|
||||||
// Record matched group with group and match ids
|
// Record matched group with group ids
|
||||||
matchName := "group_" + strconv.Itoa(groupIdx) + "_" + strconv.Itoa(matchNum)
|
matchName := "group_" + strconv.Itoa(groupIdx)
|
||||||
tmplData[matchName] = group
|
tmplData[matchName] = group
|
||||||
// Record last named group non-empty matches as group matches
|
// Record last named group non-empty matches as group matches
|
||||||
name := groupNames[groupIdx]
|
if group != "" {
|
||||||
_, ok := tmplData[name]
|
tmplData[group] = out[0][idx]
|
||||||
if name != "" && group != "" && !ok {
|
|
||||||
tmplData[name] = group
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
temp.Execute(buff, tmplData)
|
temp.Execute(buff, tmplData)
|
||||||
candidates = append(candidates, strings.TrimSpace(buff.String()))
|
candidates = append(candidates, strings.TrimSpace(buff.String()))
|
||||||
|
buff.Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
menuItems := make([]*menuItem, len(candidates))
|
menuItems := make([]*menuItem, len(candidates))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user