fix(zoxide/cd): support folder contains space
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -121,7 +122,7 @@ func FileGenerator(filters ...string) GeneratorFunc {
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
if dirOnly {
|
||||
continue
|
||||
}
|
||||
@@ -139,6 +140,10 @@ func FileGenerator(filters ...string) GeneratorFunc {
|
||||
})
|
||||
}
|
||||
|
||||
sort.Slice(results, func(i, j int) bool {
|
||||
return strings.ToLower(results[i].Cmd) < strings.ToLower(results[j].Cmd)
|
||||
})
|
||||
|
||||
return results
|
||||
}
|
||||
}
|
||||
|
||||
+14
-2
@@ -178,8 +178,20 @@ func Lookup(input string) []Suggestion {
|
||||
continue
|
||||
}
|
||||
|
||||
finalCmd := g.Cmd
|
||||
finalCmd = strings.TrimSpace(linePrefix) + " " + g.Cmd
|
||||
suggested := g.Cmd
|
||||
if strings.Contains(suggested, " ") && !strings.HasPrefix(suggested, "\"") {
|
||||
suggested = "\"" + suggested + "\""
|
||||
}
|
||||
|
||||
// if the suggestion is a full path that includes
|
||||
// words already in the command line (multi-word support), we replace
|
||||
// the entire argument part by using prefix only
|
||||
finalCmd := ""
|
||||
if len(tokens) > depth+1 && strings.HasPrefix(g.Cmd, tokens[depth]) {
|
||||
finalCmd = prefix + " " + suggested
|
||||
} else {
|
||||
finalCmd = strings.TrimSpace(linePrefix) + " " + suggested
|
||||
}
|
||||
|
||||
newTokens := tokenize(finalCmd)
|
||||
if len(newTokens) > 0 {
|
||||
|
||||
@@ -62,6 +62,7 @@ func hasPrefix(s, prefix string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// CI = case insensitive
|
||||
func HasPrefixCI(s, prefix string) bool {
|
||||
return hasPrefix(s, prefix)
|
||||
|
||||
Reference in New Issue
Block a user