2
0
mirror of https://github.com/kazhala/dotbare synced 2024-11-02 09:40:27 +00:00

feat(complete:bash): set up completion for subcommands

This commit is contained in:
kevin zhuang 2020-06-06 10:31:06 +10:00
parent a6052af017
commit 1b648d4c3f

View File

@ -1,2 +1,24 @@
mydir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
[[ :$PATH: != *:"${mydir}":* ]] && export PATH="$PATH:${mydir}"
_dotbare_completions()
{
local IFS=$'\n' subcommands
if [[ "$COMP_CWORD" -eq "1" ]]; then
subcommands="$(./dotbare -h \
| awk '{
if ($0 ~ /^ f.*/) {
gsub(/^ /, "", $0)
gsub(/\t\t/, " ", $0)
print $0
}
}')"
COMPREPLY=($(compgen -W "${subcommands}" -- "${COMP_WORDS[1]}"))
if [[ ${#COMPREPLY[*]} -eq 1 ]]; then
COMPREPLY=( ${COMPREPLY[0]%% *} )
fi
fi
}
complete -F _dotbare_completions dotbare