Repository: jesseduffield/lazygit
File: pkg/gui/custom_commands.go (Go)

Code before:
			case "menuFromCommand":
				f = func() error {
                                        // Collect cmd to run from config
			                cmdStr, err := gui.resolveTemplate(prompt.Command, promptResponses)
			                if err != nil {
			                	return gui.surfaceError(err)
			                }

                                        // Collect Filter regexp
			                filter, err := gui.resolveTemplate(prompt.Filter, promptResponses)
			                if err != nil {
			                	return gui.surfaceError(err)
			                }

                                        // Run and save output
                                        message,err := gui.GitCommand.RunCommandWithOutput(cmdStr)
			                if err != nil {
			                	return gui.surfaceError(err)
			                }

					// Need to make a menu out of what the cmd has displayed
                                        var candidates []string
                                        reg := regexp.MustCompile(filter)
                                        for _,str := range strings.Split(string(message), "\n"){
                                            cand := ""
                                            if str != "" {
					        for i := 1; i < (reg.NumSubexp()+1); i++ {
                                                    keep := reg.ReplaceAllString(str, "${"+fmt.Sprint(i)+"}")
                                                    cand += keep
                                                }
                                                candidates = append(candidates, cand)
                                            }
                                        }

					menuItems := make([]*menuItem, len(candidates))
					for i, option := range candidates {
						option := option

						menuItems[i] = &menuItem{
							displayStrings: []string{option},
							onPress: func() error {
								promptResponses[idx] = option

								return wrappedF()
							},
						}
					}

					title, err := gui.resolveTemplate(prompt.Title, promptResponses)
					if err != nil {
						return gui.surfaceError(err)

Review comment (suggestion):
Can you reverse this check to:
```go
if str == "" {
  continue
}
```

Code after:
}

func (gui *Gui) menuPromptFromCommand(prompt config.CustomCommandPrompt, promptResponses []string, responseIdx int, wrappedF func() error) error {
	// Collect cmd to run from config
	cmdStr, err := gui.resolveTemplate(prompt.Command, promptResponses)
	if err != nil {
		return gui.surfaceError(err)
	}

	// Collect Filter regexp
	filter, err := gui.resolveTemplate(prompt.Filter, promptResponses)
	if err != nil {
		return gui.surfaceError(err)
	}

	// Run and save output
	message, err := gui.GitCommand.RunCommandWithOutput(cmdStr)
	if err != nil {
		return gui.surfaceError(err)
	}

	// Need to make a menu out of what the cmd has displayed
	candidates, err := gui.GenerateMenuCandidates(message, filter, prompt.Format)
	if err != nil {
		return gui.surfaceError(err)
	}

	menuItems := make([]*menuItem, len(candidates))
	for i := range candidates {
		menuItems[i] = &menuItem{
			displayStrings: []string{candidates[i]},
			onPress: func() error {
				promptResponses[responseIdx] = candidates[i]
				return wrappedF()
			},
		}
	}

	title, err := gui.resolveTemplate(prompt.Title, promptResponses)
	if err != nil {
		return gui.surfaceError(err)
	}

	return gui.createMenu(title, menuItems, createMenuOptions{showCancel: true})
}

func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand) func() error {
	return func() error {
		promptResponses := make([]string, len(customCommand.Prompts))

		f := func() error {