Skip to content

Commit

Permalink
add search feature to branch subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
isacikgoz committed Feb 6, 2019
1 parent 680b327 commit 710591d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cli/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"strings"

"github.com/isacikgoz/gitin/git"
"github.com/isacikgoz/promptui"
Expand Down Expand Up @@ -60,6 +61,13 @@ func branchPrompt(r *git.Repository, opts *PromptOptions) error {
fmt.Printf("\x1b[?7l")
// defer restoring line wrap
defer fmt.Printf("\x1b[?7h")
searcher := func(input string, index int) bool {
item := r.Branches[index]
name := strings.Replace(strings.ToLower(item.Name), " ", "", -1)
input = strings.Replace(strings.ToLower(input), " ", "", -1)

return strings.Contains(name, input)
}

var prompt promptui.Select
kset := make(map[rune]promptui.CustomFunc)
Expand Down Expand Up @@ -90,6 +98,7 @@ func branchPrompt(r *git.Repository, opts *PromptOptions) error {
Label: "Branches",
Items: r.Branches,
HideHelp: opts.HideHelp,
Searcher: searcher,
Size: opts.Size,
Templates: branchTemplate(),
CustomFuncs: kset,
Expand Down

0 comments on commit 710591d

Please sign in to comment.