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
+7 -1
View File
@@ -1,6 +1,8 @@
package fs
import (
"strings"
"github.com/versenilvis/iris/commands/core"
)
@@ -8,6 +10,10 @@ func init() {
core.Register(&core.Spec{
Name: "cd",
Description: "change directory",
Generator: core.FileGenerator("/"), // Directory only
MaxArgs: 0,
Generator: func(tokens []string, prefix string, partial string) []core.Suggestion {
fullQuery := strings.Join(tokens[1:], " ")
return core.FileGenerator("/")(tokens, prefix, fullQuery)
},
})
}
+7 -8
View File
@@ -18,21 +18,21 @@ func init() {
core.Register(&core.Spec{
Name: "z",
Description: "jump to directory",
MaxArgs: 1,
MaxArgs: 0,
Generator: zoxideGenerator(),
})
core.Register(&core.Spec{
Name: "zi",
Description: "jump to directory interactively",
MaxArgs: 1,
MaxArgs: 0,
Generator: zoxideGenerator(),
})
}
func zoxideGenerator() core.GeneratorFunc {
return func(tokens []string, prefix string, partial string) []core.Suggestion {
localSuggestions := core.FileGenerator("/")(tokens, prefix, partial)
fullQuery := strings.Join(tokens[1:], " ")
localSuggestions := core.FileGenerator("/")(tokens, prefix, fullQuery)
var zoxideSuggestions []core.Suggestion
cmd := exec.Command("zoxide", "query", "-l")
@@ -49,7 +49,7 @@ func zoxideGenerator() core.GeneratorFunc {
home, _ := os.UserHomeDir()
if partial == "" {
if fullQuery == "" {
limit := 20
if len(dirs) < limit {
limit = len(dirs)
@@ -62,10 +62,9 @@ func zoxideGenerator() core.GeneratorFunc {
Desc: display,
})
}
} else if !strings.Contains(partial, "/") {
} else if !strings.Contains(fullQuery, "/") {
searcher := fuzzyvn.NewPlainSearcher(dirs)
matches := searcher.SearchWithScores(partial, &fuzzyvn.SearchOptions{Limit: 10})
matches := searcher.SearchWithScores(fullQuery, &fuzzyvn.SearchOptions{Limit: 10})
for _, m := range matches {
path := m.Str
display := strings.Replace(path, home, "~", 1)