Skip to content

Commit

Permalink
runner: add use_fd flag to use fd for searching for executables
Browse files Browse the repository at this point in the history
  • Loading branch information
abenz1267 committed Jan 14, 2025
1 parent 15cba1d commit 5ba2c3c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
1 change: 1 addition & 0 deletions internal/config/config.default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ typeahead = true
history = true
generic_entry = false
refresh = true
use_fd = false

[builtins.ssh]
weight = 5
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
46 changes: 31 additions & 15 deletions internal/modules/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package modules

import (
"bufio"
"bytes"
"fmt"
"io/fs"
"log"
Expand All @@ -10,6 +11,7 @@ import (
"path/filepath"
"slices"
"strings"
"time"

"github.com/abenz1267/walker/internal/config"
"github.com/abenz1267/walker/internal/util"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 5ba2c3c

Please sign in to comment.