Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean capistrano completions and add options completions #2133

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ completion/available/apm.completion.bash
completion/available/awless.completion.bash
completion/available/bash-it.completion.bash
completion/available/brew.completion.bash
completion/available/capistrano.completion.bash
completion/available/cargo.completion.bash
completion/available/composer.completion.bash
completion/available/conda.completion.bash
Expand Down
50 changes: 31 additions & 19 deletions completion/available/capistrano.completion.bash
Original file line number Diff line number Diff line change
@@ -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
# 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
}
if _command_exists cap; then
function __cap_completions() {
[[ ! -f Capfile ]] && return 1

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