-
Notifications
You must be signed in to change notification settings - Fork 1
/
bash.go
49 lines (43 loc) · 1.29 KB
/
bash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package bridges
import (
"os"
"runtime"
"strings"
"github.com/rsteube/carapace"
"github.com/rsteube/carapace/pkg/execlog"
)
func Bash() []string {
if runtime.GOOS == "windows" {
return []string{}
}
if _, err := execlog.LookPath("bash"); err != nil {
return []string{}
}
return cache("bash", func() ([]string, error) {
unique := make(map[string]bool)
for _, location := range []string{
"/data/data/com.termux/files/etc/bash_completion.d", // termux
"/data/data/com.termux/files/usr/share/bash-completion/completions", // termux
"/etc/bash_completion.d", // linux
"/usr/local/etc/bash_completion.d", // osx
"/usr/local/share/bash-completion/completions", // osx
"/usr/share/bash-completion/completions", // linux
} {
entries, err := os.ReadDir(location)
if err != nil {
carapace.LOG.Println(err.Error())
continue
}
for _, entry := range entries {
if !entry.IsDir() && !strings.HasPrefix(entry.Name(), "_") {
unique[entry.Name()] = true
}
}
}
completers := make([]string, 0)
for c := range filter(unique, bashBuiltins) {
completers = append(completers, c)
}
return completers, nil
})
}