Skip to content

Commit

Permalink
Merge pull request #4 from jacobwgillespie/complete-executables
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie authored Apr 11, 2022
2 parents 0c6afbc + 2f845a8 commit d160173
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 d160173

Please sign in to comment.