Skip to content

Commit

Permalink
Add node_modules/.bin executables to completion
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie committed Apr 11, 2022
1 parent 0c6afbc commit 2f845a8
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path/filepath"
"sort"
"strings"

"golang.org/x/exp/maps"
Expand Down Expand Up @@ -62,9 +63,36 @@ func listScripts() []string {
return empty
}
if pkg.Scripts == nil {
return empty
pkg.Scripts = &map[string]string{}
}

// Add all executibles to the script list
binDirs := findBinDirs(cwd)
for _, dir := range binDirs {
files, err := os.ReadDir(dir)
if err != nil {
continue
}
for _, file := range files {
if file.IsDir() {
continue
}
if _, ok := (*pkg.Scripts)[file.Name()]; ok {
continue
}
info, err := os.Stat(filepath.Join(dir, file.Name()))
if err != nil {
continue
}
if info.Mode()&0111 != 0 {
(*pkg.Scripts)[file.Name()] = ""
}
}
}
return maps.Keys(*pkg.Scripts)

scripts := maps.Keys(*pkg.Scripts)
sort.Strings(scripts)
return scripts
}

func resolveBinary(name string, binDirs []string) (string, error) {
Expand Down

0 comments on commit 2f845a8

Please sign in to comment.