Merge pull request #7 from kazhala/feat/completion-bash

Feat/completion bash
pull/18/head
Kevin Zhuang 4 years ago committed by GitHub
commit 1b24185545
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -139,6 +139,10 @@ antigen bundle kazhala/dotbare
### bash
dotbare comes with a `dotbare.plugin.bash` which will enable both bash command line
completion for dotbare commands and adding dotbare to your PATH. If you don't want the completion,
simple follow the instructions in [Others](#Others) and add dotbare to your PATH.
- Clone the repository (change ~/.dotbare to the location of your preference)
```sh

@ -1,2 +1,83 @@
mydir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
[[ :$PATH: != *:"${mydir}":* ]] && export PATH="$PATH:${mydir}"
_dotbare_completions()
{
local IFS=$'\n' subcommands curr prev options
curr="${COMP_WORDS[$COMP_CWORD]}"
prev="${COMP_WORDS[$COMP_CWORD-1]}"
if [[ "$COMP_CWORD" -eq "1" ]]; then
subcommands=$("${mydir}"/dotbare -h \
| awk '{
if ($0 ~ /^ f.*/) {
gsub(/^ /, "", $0)
gsub(/\t\t/, " ", $0)
print $0
}
}')
if [[ $curr == -* ]]; then
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "-h" -- "${curr}"))
else
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "${subcommands}" -- "${curr}"))
fi
if [[ ${#COMPREPLY[*]} -eq 1 ]]; then
COMPREPLY=( "${COMPREPLY[0]%% *}" )
fi
elif [[ "$COMP_CWORD" -eq "2" && "${prev}" != '-h' ]]; then
case "${prev}" in
fbackup)
options=$("${mydir}"/dotbare "${prev}" -h \
| awk '{
if ($0 ~ / -p PATH/) {
gsub(/^ -p PATH/, "-p ", $0)
gsub(/\t/, " ", $0)
print $0
} else if ($0 ~ / -*/) {
gsub(/^ /, "", $0)
gsub(/\t/, " ", $0)
print $0
}
}')
;;
finit)
options=$("${mydir}"/dotbare "${prev}" -h \
| awk '{
if ($0 ~ / -u URL/) {
gsub(/^ -u URL/, "-u ", $0)
gsub(/\t/, " ", $0)
print $0
} else if ($0 ~ / -*/) {
gsub(/^ /, "", $0)
gsub(/\t/, " ", $0)
print $0
}
}')
;;
*)
options=$("${mydir}"/dotbare "${prev}" -h \
| awk '{
if ($0 ~ / -*/) {
gsub(/^ /, "", $0)
gsub(/\t/, " ", $0)
print $0
}
}')
;;
esac
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "${options}" -- "${curr}"))
if [[ ${#COMPREPLY[*]} -eq 1 ]]; then
COMPREPLY=( "${COMPREPLY[0]%% *}" )
fi
elif [[ "$COMP_CWORD" -eq "3" ]]; then
# shellcheck disable=SC2207
[[ "${COMP_WORDS[1]}" == "fbackup" && "${COMP_WORDS[2]}" == "-p" ]] && \
COMPREPLY=($(compgen -d -- "${curr}"))
fi
}
complete -F _dotbare_completions dotbare

@ -21,5 +21,6 @@ done < <(
)
shellcheck -e SC1090 "${scripts[@]}"
shellcheck -e SC1090 --shell=bash "dotbare.plugin.bash"
exit $?

Loading…
Cancel
Save