fix(zoxide/cd): support folder contains space

This commit is contained in:
verse91
2026-05-09 22:54:27 +07:00
parent 5f4a11edf0
commit 3c5a0580d1
5 changed files with 35 additions and 12 deletions
+6 -1
View File
@@ -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
View File
@@ -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 {
+1
View File
@@ -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)