From 5ba2c3c9134c2b15a4ecbdfcabddb2c62bfadd9f Mon Sep 17 00:00:00 2001 From: Andrej Benz Date: Tue, 14 Jan 2025 20:12:23 +0100 Subject: [PATCH] runner: add `use_fd` flag to use `fd` for searching for executables --- internal/config/config.default.toml | 1 + internal/config/config.go | 1 + internal/modules/runner.go | 46 +++++++++++++++++++---------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/internal/config/config.default.toml b/internal/config/config.default.toml index 42b8786..77c8621 100644 --- a/internal/config/config.default.toml +++ b/internal/config/config.default.toml @@ -186,6 +186,7 @@ typeahead = true history = true generic_entry = false refresh = true +use_fd = false [builtins.ssh] weight = 5 diff --git a/internal/config/config.go b/internal/config/config.go index 5bf034c..de0a5c8 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -327,6 +327,7 @@ type Runner struct { Includes []string `koanf:"includes"` ShellConfig string `koanf:"shell_config"` GenericEntry bool `koanf:"generic_entry"` + UseFD bool `koanf:"use_fd"` } type Plugin struct { diff --git a/internal/modules/runner.go b/internal/modules/runner.go index 128b73b..e6f1d1b 100644 --- a/internal/modules/runner.go +++ b/internal/modules/runner.go @@ -2,6 +2,7 @@ package modules import ( "bufio" + "bytes" "fmt" "io/fs" "log" @@ -10,6 +11,7 @@ import ( "path/filepath" "slices" "strings" + "time" "github.com/abenz1267/walker/internal/config" "github.com/abenz1267/walker/internal/util" @@ -141,31 +143,45 @@ func (r *Runner) getBins() { bins := []string{} - for _, p := range paths { - filepath.WalkDir(p, func(path string, d fs.DirEntry, err error) error { - if d != nil && d.IsDir() { - return nil - } + now := time.Now() - info, err := os.Stat("file/directory name") + if config.Cfg.Builtins.Runner.UseFD { + args := []string{".", "--no-ignore-vcs", "--type", "executable"} + args = append(args, paths...) - if info == nil { - return nil + cmd := exec.Command("fd", args...) + + out, err := cmd.CombinedOutput() + if err == nil { + scanner := bufio.NewScanner(bytes.NewReader(out)) + + for scanner.Scan() { + bins = append(bins, filepath.Base(scanner.Text())) } + } + } else { + for _, p := range paths { + filepath.WalkDir(p, func(path string, d fs.DirEntry, err error) error { + if d != nil && d.IsDir() { + return nil + } - if info.Mode()&0111 != 0 { - exec, _ := exec.LookPath(filepath.Base(path)) - if exec == "" { + info, err := os.Stat(path) + if info == nil { return nil } - bins = append(bins, filepath.Base(path)) - } + if info.Mode()&0111 != 0 { + bins = append(bins, filepath.Base(path)) + } - return nil - }) + return nil + }) + } } + fmt.Println(time.Since(now)) + for k := range r.aliases { bins = append(bins, k) }