Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/actions/bridge/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func ActionAws(command ...string) carapace.Action {
return carapace.ActionValues()
}
for index, line := range lines {
if strings.HasSuffix(line, " ") {
lines[index] = strings.TrimSuffix(line, " ") // v1 has space suffix
if before, ok := strings.CutSuffix(line, " "); ok {
lines[index] = before // v1 has space suffix
}
}
a := carapace.ActionValues(lines[:len(lines)-1]...)
Expand Down
64 changes: 19 additions & 45 deletions pkg/bridges/bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,14 @@ func Bash() []string {

// bashCompletionLocations return folders containing bash completion scripts
//
// https://github.com/scop/bash-completion/blob/7864377cacb7858893a475e69c9c7461c2727e02/bash_completion#L3159C5-L3194C61
// https://github.com/scop/bash-completion/blob/main/bash_completion (function _comp_load)
func bashCompletionLocations() []string {
locations := []string{
// TODO fix order
"/data/data/com.termux/files/etc/bash_completion.d", // termux
"/etc/bash_completion.d", // linux
"/usr/local/etc/bash_completion.d", // osx
}
var locations []string

// # Lookup order:
// # 1) From BASH_COMPLETION_USER_DIR (e.g. ~/.local/share/bash-completion):
// # User installed completions.
// if [[ ${BASH_COMPLETION_USER_DIR-} ]]; then
// _comp_split -F : paths "$BASH_COMPLETION_USER_DIR" &&
// dirs+=("${paths[@]/%//completions}")
// else
// dirs=("${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion/completions")
// fi
// 1) From BASH_COMPLETION_USER_DIR or XDG_DATA_HOME:
// User installed completions are looked up first.
if userDirs, ok := os.LookupEnv("BASH_COMPLETION_USER_DIR"); ok {
for userDir := range strings.Split(userDirs, string(os.PathListSeparator)) {
for userDir := range strings.SplitSeq(userDirs, string(os.PathListSeparator)) {
locations = append(locations, fmt.Sprintf("%v/completions", userDir))
}
} else {
Expand All @@ -73,42 +61,21 @@ func bashCompletionLocations() []string {
}
}

// # 2) From the location of bash_completion: Completions relative to the main
// # script. This is primarily for run-in-place-from-git-clone setups, where
// # we want to prefer in-tree completions over ones possibly coming with a
// # system installed bash-completion. (Due to usual install layouts, this
// # often hits the correct completions in system installations, too.)
// if [[ $BASH_SOURCE == */* ]]; then
// dirs+=("${BASH_SOURCE%/*}/completions")
// else
// dirs+=(./completions)
// fi
// 2) From the location of bash_completion (completions relative to the main script).
// In system installations this often hits the right directory.
if sourceDir, ok := os.LookupEnv("BASH_SOURCE"); ok {
locations = append(locations, fmt.Sprintf("%v/completions", sourceDir))
} else {
locations = append(locations, "./completions")
}

// # 3) From bin directories extracted from the specified path to the command,
// # the real path to the command, and $PATH
// paths=()
// [[ $cmd == /* ]] && paths+=("${cmd%/*}")
// _comp_realcommand "$cmd" && paths+=("${REPLY%/*}")
// _comp_split -aF : paths "$PATH"
// for dir in "${paths[@]%/}"; do
// [[ $dir == ?*/@(bin|sbin) ]] &&
// dirs+=("${dir%/*}/share/bash-completion/completions")
// done
for _, pathDir := range strings.Split(os.Getenv("PATH"), string(os.PathListSeparator)) {
// 3) From bin directories extracted from $PATH.
// For each PATH entry ending in bin or sbin, look at ../share/bash-completion/completions.
for pathDir := range strings.SplitSeq(os.Getenv("PATH"), string(os.PathListSeparator)) {
locations = append(locations, fmt.Sprintf("%v/share/bash-completion/completions", pathDir))
}

// # 4) From XDG_DATA_DIRS or system dirs (e.g. /usr/share, /usr/local/share):
// # Completions in the system data dirs.
// _comp_split -F : paths "${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" &&
// dirs+=("${paths[@]/%//bash-completion/completions}")
// 4) From XDG_DATA_DIRS or system data dirs.
if dataDirs, ok := os.LookupEnv("XDG_DATA_DIRS"); ok {
for _, dataDir := range strings.Split(dataDirs, string(os.PathListSeparator)) {
for dataDir := range strings.SplitSeq(dataDirs, string(os.PathListSeparator)) {
locations = append(locations, fmt.Sprintf("%v/bash-completion/completions", dataDir))
}
} else {
Expand All @@ -119,5 +86,12 @@ func bashCompletionLocations() []string {
)
}

// 5) Legacy/fallback locations (pre-XDG system dirs).
locations = append(locations,
"/data/data/com.termux/files/etc/bash_completion.d", // termux
"/etc/bash_completion.d", // linux
"/usr/local/etc/bash_completion.d", // osx
)

return locations
}
25 changes: 25 additions & 0 deletions pkg/bridges/bash_builtins.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,81 @@
package bridges

// compgen -b; compgen -k
var bashBuiltins = []string{
"!",
".",
":",
"[",
"[[",
"]]",
"{",
"}",
"alias",
"bg",
"bind",
"break",
"builtin",
"caller",
"case",
"cd",
"command",
"compgen",
"complete",
"compopt",
"continue",
"coproc",
"declare",
"dirs",
"disown",
"do",
"done",
"echo",
"elif",
"else",
"enable",
"esac",
"eval",
"exec",
"exit",
"export",
"false",
"fc",
"fg",
"fi",
"for",
"function",
"getopts",
"hash",
"help",
"history",
"if",
"in",
"jobs",
"kill",
"let",
"local",
"logout",
"mapfile",
"popd",
"printf",
"pushd",
"pwd",
"read",
"readarray",
"readonly",
"return",
"select",
"set",
"shift",
"shopt",
"source",
"suspend",
"test",
"then",
"time",
"times",
"trap",
"true",
"type",
"typeset",
"ulimit",
Expand Down