Enhance lookup mechanics and priority propagation (`spec/lookup.go`) Remove the requirement of typing a leading `-` when searching for options, allowing flag suggestions to surface naturally during input Accurately forward the `Priority` field from registry specs into the `Suggestion` struct so the scoring engine evaluates relevance properly Integrate scoring into the main suggestion pipeline (`root/suggestions.go`) Collect context signals using `scoring.CollectSignals(cwd, query, rootCmd, store)` with the live working directory retrieved from `spec.GetCWD()` Pass the entire deduplicated list across spec, history and AI items through `scoring.Score(deduped, signals)` to compute scores and sort by descending order before rendering on screen Record execution history in Frecency Store (`root/wrapper.go`) Save the last executed command to `lastSubmittedCommand` whenever Enter is pressed or a suggestion is selected Trigger `store.Record(...)` asynchronously within the `IRIS_CMD_STOP` hook using a dedicated goroutine guarded by panic recovery and timeout limits, preventing blocks on the main shell thread Optimize workspace identification for AI (`internal/ai/context_provider.go`) Use `workspace.DetectCached(cwd)` to instantly fetch ecosystem context across Git, Node, Go, Rust, Python and Docker alongside active git branch state This caching mechanism avoids redundant subprocess execution when outside git repositories, significantly speeding up prompt context generation
92 lines
2.2 KiB
Go
92 lines
2.2 KiB
Go
// please note that zoxide also shows external suggestions
|
|
// at the end of the list on command mode
|
|
// they are the old directories that you have visited
|
|
// this is a feature, not a bug, and I want to keep it
|
|
package fs
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/versenilvis/fuzzy"
|
|
"github.com/versenilvis/iris/spec"
|
|
)
|
|
|
|
func init() {
|
|
spec.Register(&spec.Spec{
|
|
Name: "z",
|
|
Description: "jump to directory",
|
|
MaxArgs: 0,
|
|
Generator: ZoxideGenerator(),
|
|
})
|
|
spec.Register(&spec.Spec{
|
|
Name: "zi",
|
|
Description: "jump to directory interactively",
|
|
MaxArgs: 0,
|
|
Generator: ZoxideGenerator(),
|
|
})
|
|
}
|
|
|
|
func ZoxideGenerator() spec.GeneratorFunc {
|
|
return func(tokens []string, prefix string, partial string) []spec.Suggestion {
|
|
fullQuery := strings.Join(tokens[1:], " ")
|
|
localSuggestions := spec.FileGenerator("/")(tokens, prefix, fullQuery)
|
|
|
|
var zoxideSuggestions []spec.Suggestion
|
|
cmd := exec.CommandContext(context.Background(), "zoxide", "query", "-l")
|
|
out, err := cmd.Output()
|
|
if err == nil {
|
|
lines := strings.Split(string(bytes.TrimSpace(out)), "\n")
|
|
var dirs []string
|
|
for _, line := range lines {
|
|
line = strings.TrimSpace(line)
|
|
if line != "" {
|
|
dirs = append(dirs, line)
|
|
}
|
|
}
|
|
|
|
home, _ := os.UserHomeDir()
|
|
|
|
if fullQuery == "" {
|
|
limit := min(len(dirs), 20)
|
|
for i := range limit {
|
|
path := dirs[i]
|
|
display := strings.Replace(path, home, "~", 1)
|
|
zoxideSuggestions = append(zoxideSuggestions, spec.Suggestion{
|
|
Cmd: path,
|
|
Desc: display,
|
|
})
|
|
}
|
|
} else if !strings.Contains(fullQuery, "/") {
|
|
searcher := fuzzy.NewPlainSearcher(dirs)
|
|
matches := searcher.SearchWithScores(fullQuery, &fuzzy.SearchOptions{Limit: 10})
|
|
for _, m := range matches {
|
|
path := m.Str
|
|
display := strings.Replace(path, home, "~", 1)
|
|
zoxideSuggestions = append(zoxideSuggestions, spec.Suggestion{
|
|
Cmd: path,
|
|
Desc: display,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
var finalResults []spec.Suggestion
|
|
seen := make(map[string]bool)
|
|
|
|
finalResults = append(finalResults, localSuggestions...)
|
|
|
|
for _, s := range zoxideSuggestions {
|
|
if !seen[s.Cmd] {
|
|
finalResults = append(finalResults, s)
|
|
seen[s.Cmd] = true
|
|
}
|
|
}
|
|
|
|
return finalResults
|
|
}
|
|
}
|