fix (completion): remove file dependencies and add more completion for options
parent
e1ddf6e311
commit
7f17c8f827
|
|
@ -1,24 +1,36 @@
|
||||||
#!/usr/bin/env bash
|
# shellcheck shell=bash
|
||||||
# Bash completion support for Capistrano.
|
# Bash completion support for Capistrano.
|
||||||
|
|
||||||
export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/}
|
export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/}
|
||||||
|
|
||||||
_capcomplete() {
|
if _command_exists cap; then
|
||||||
if [ -f Capfile ]; then
|
function __cap_completions() {
|
||||||
recent=`ls -t .cap_tasks~ Capfile **/*.cap 2> /dev/null | head -n 1`
|
[[ ! -f Capfile ]] && return 1
|
||||||
if [[ $recent != '.cap_tasks~' ]]; then
|
|
||||||
cap --version | grep 'Capistrano v2.' > /dev/null
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
# Capistrano 2.x
|
|
||||||
cap --tool --verbose --tasks | cut -d " " -f 2 > .cap_tasks~
|
|
||||||
else
|
|
||||||
# Capistrano 3.x
|
|
||||||
cap --all --tasks | cut -d " " -f 2 > .cap_tasks~
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
COMPREPLY=($(compgen -W "`cat .cap_tasks~`" -- ${COMP_WORDS[COMP_CWORD]}))
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
complete -o default -o nospace -F _capcomplete cap
|
local cword
|
||||||
|
cword=$(_get_cword)
|
||||||
|
|
||||||
|
case $cword in
|
||||||
|
-*)
|
||||||
|
# Complete options
|
||||||
|
COMPREPLY=(--{suppress-,}backtrace --comments --job-stats --rules -A --all -B --build-all -C --directory -D --describe -e -E --execute{,-continue,-print} -f --rakefile
|
||||||
|
-G --{no{-,},}system -g -I --libdir -j --jobs -m --multitask -N --no{-,}search -P --prereqs --require -R --rakelib{dir,} -t --trace -T --tasks -W --where -X --no-deprecation-warning
|
||||||
|
-V --version -n --dry-run -r --roles -z --hosts -p --print-config-variables -h -H --help)
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
# Complete tasks
|
||||||
|
if cap --version | grep 'Capistrano v2.' > /dev/null; then
|
||||||
|
# Capistrano 2.x
|
||||||
|
read -ra COMPREPLY < <(cap --tool --verbose --tasks | awk '{print $2}' | tr '\n' ' ')
|
||||||
|
else
|
||||||
|
# Capistrano 3.x
|
||||||
|
read -ra COMPREPLY < <(cap --all --tasks | awk '{print $2}' | tr '\n' ' ')
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
complete -F __cap_completions -X "!&*" cap
|
||||||
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue