Skip to content

Commit

Permalink
bash: load completion
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jan 17, 2024
1 parent 6f4af4a commit 2337a6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 6 additions & 1 deletion pkg/actions/bridge/bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ func ActionBash(command ...string) carapace.Action {
vals = append(vals, strings.TrimSpace(line), "")
}
}
return carapace.ActionValuesDescribed(vals...).StyleF(style.ForPath)
switch len(vals) {
case 0:
return carapace.ActionFiles()
default:
return carapace.ActionValuesDescribed(vals...).StyleF(style.ForPath)
}
}).Invoke(c).ToA().NoSpace([]rune("/=@:.,")...) // TODO check compopt for nospace
})
}
11 changes: 6 additions & 5 deletions pkg/actions/bridge/bash.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#!/bin/bash

[ -f /usr/local/etc/bash_completion ] && source /usr/local/etc/bash_completion # osx
[ -f /usr/share/bash-completion/bash_completion ] && source /usr/share/bash-completion/bash_completion # linux
[ -f /data/data/com.termux/files/usr/share/bash-completion/bash_completion ] && source /data/data/com.termux/files/usr/share/bash-completion/bash_completion # termux

# COMP_LINE="$1"
COMP_WORDS=($COMP_LINE)
if [ "${COMP_LINE: -1}" = " " ]; then
COMP_WORDS+=("")
fi
COMP_CWORD=$((${#COMP_WORDS[@]} - 1))
COMP_POINT=${#COMP_LINE}

# bash-completions
[ -f /usr/local/etc/bash_completion ] && source /usr/local/etc/bash_completion # osx
[ -f /usr/share/bash-completion/bash_completion ] && source /usr/share/bash-completion/bash_completion # linux
[ -f /data/data/com.termux/files/usr/share/bash-completion/bash_completion ] && source /data/data/com.termux/files/usr/share/bash-completion/bash_completion # termux
__load_completion "${COMP_WORDS[0]}"

$"$(complete -p "${COMP_WORDS[0]}" | sed -r 's/.* -F ([^ ]+).*/\1/')"

for i in "${COMPREPLY[@]}"; do
Expand Down

0 comments on commit 2337a6d

Please sign in to comment.