Skip to content

Commit d160173

Browse files
Merge pull request #4 from jacobwgillespie/complete-executables
2 parents 0c6afbc + 2f845a8 commit d160173

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

utils.go

+30-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/exec"
88
"path/filepath"
9+
"sort"
910
"strings"
1011

1112
"golang.org/x/exp/maps"
@@ -62,9 +63,36 @@ func listScripts() []string {
6263
return empty
6364
}
6465
if pkg.Scripts == nil {
65-
return empty
66+
pkg.Scripts = &map[string]string{}
67+
}
68+
69+
// Add all executibles to the script list
70+
binDirs := findBinDirs(cwd)
71+
for _, dir := range binDirs {
72+
files, err := os.ReadDir(dir)
73+
if err != nil {
74+
continue
75+
}
76+
for _, file := range files {
77+
if file.IsDir() {
78+
continue
79+
}
80+
if _, ok := (*pkg.Scripts)[file.Name()]; ok {
81+
continue
82+
}
83+
info, err := os.Stat(filepath.Join(dir, file.Name()))
84+
if err != nil {
85+
continue
86+
}
87+
if info.Mode()&0111 != 0 {
88+
(*pkg.Scripts)[file.Name()] = ""
89+
}
90+
}
6691
}
67-
return maps.Keys(*pkg.Scripts)
92+
93+
scripts := maps.Keys(*pkg.Scripts)
94+
sort.Strings(scripts)
95+
return scripts
6896
}
6997

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

0 commit comments

Comments
 (0)