@@ -3,6 +3,8 @@ package cmd
33import (
44 "fmt"
55 "github.com/chriswalz/complete/v3"
6+ "github.com/google/shlex"
7+ "github.com/lithammer/fuzzysearch/fuzzy"
68 "os"
79 "sort"
810 "strings"
@@ -79,20 +81,41 @@ func specificCommandCompleter(subCmd string, suggestionMap *complete.CompTree) f
7981 }
8082}
8183
84+ var fuzzyQuery = func (s , prefix string ) bool {
85+ return fuzzy .Match (prefix , s )
86+ }
87+
8288func promptCompleter (suggestionTree * complete.CompTree , text string ) []prompt.Suggest {
8389 text = "bit " + text
8490
8591 var sugg []prompt.Suggest
8692
87- suggestions , err := complete .CompleteLine (text , suggestionTree )
93+ queryFunc := strings .HasPrefix
94+
95+ split , err := shlex .Split (strings .TrimSpace (text ))
8896 if err != nil {
8997 log .Debug ().Err (err ).Send ()
9098 return sugg
9199 }
92- split := strings .Split (strings .TrimSpace (text ), " " )
93100 lastToken := split [len (split )- 1 ]
101+ lastCommand := lastToken
102+ if ! strings .HasSuffix (text , " " ) && len (split ) >= 2 {
103+ lastCommand = split [len (split )- 2 ]
104+ }
105+
106+ // use fuzzy search completion when querying branch names
107+ if isBranchCompletionCommand (lastCommand ) {
108+ queryFunc = fuzzyQuery
109+ }
110+
111+ suggestions , err := complete .CompleteLine (text , suggestionTree , queryFunc )
112+ if err != nil {
113+ log .Debug ().Err (err ).Send ()
114+ return sugg
115+ }
116+
94117 // for branches dont undo most recent sorts with alphabetical sort
95- if ! isBranchCompletionCommand (lastToken ) {
118+ if ! isBranchCompletionCommand (lastCommand ) {
96119 sort .Slice (suggestions , func (i , j int ) bool {
97120 return suggestions [i ].Name < suggestions [j ].Name
98121 })
0 commit comments