fix (completion): remove file dependencies and add more completion for options

pull/2133/head
Gurkirat Singh 2022-03-15 07:23:17 +05:30
parent e1ddf6e311
commit 7f17c8f827
No known key found for this signature in database
GPG Key ID: 5C2602348A8FACE1
1 changed files with 31 additions and 19 deletions

View File

@ -1,24 +1,36 @@
#!/usr/bin/env bash
# shellcheck shell=bash
# Bash completion support for Capistrano.
export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/}
_capcomplete() {
if [ -f Capfile ]; then
recent=`ls -t .cap_tasks~ Capfile **/*.cap 2> /dev/null | head -n 1`
if [[ $recent != '.cap_tasks~' ]]; then
cap --version | grep 'Capistrano v2.' > /dev/null
if [ $? -eq 0 ]; then
if _command_exists cap; then
function __cap_completions() {
[[ ! -f Capfile ]] && return 1
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
cap --tool --verbose --tasks | cut -d " " -f 2 > .cap_tasks~
read -ra COMPREPLY < <(cap --tool --verbose --tasks | awk '{print $2}' | tr '\n' ' ')
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
read -ra COMPREPLY < <(cap --all --tasks | awk '{print $2}' | tr '\n' ' ')
fi
;;
esac
}
complete -o default -o nospace -F _capcomplete cap
complete -F __cap_completions -X "!&*" cap
fi