Created
October 6, 2017 20:10
-
-
Save caseywilliams/278f31a8abe68e2b8cdfa44fda63c51a to your computer and use it in GitHub Desktop.
Vanagon bash completion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bash completion for `bundle exec` or `be` in directories that look like vanagon packaging repos | |
_vanagon_actions() | |
{ | |
if [[ -d ./configs/projects && -d ./configs/platforms ]]; then | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
projects=`ls ./configs/projects/*.rb 2>/dev/null | xargs -n 1 basename | rev | cut -c 4- | rev` | |
platforms=`ls ./configs/platforms/*.rb 2>/dev/null | xargs -n 1 basename | rev | cut -c 4- | rev` | |
if [[ ${prev} =~ (^| )(be|exec)($| ) ]]; then | |
COMPREPLY=( $(compgen -W "build inspect devkit" -- ${cur}) ) | |
elif [[ ${prev} =~ (^| )bundle($| ) ]]; then | |
COMPREPLY=( $(compgen -W "exec install" -- ${cur}) ) | |
elif [[ ${prev} =~ (^| )(build|inspect|devkit)($| ) ]] ; then | |
# complete projects | |
COMPREPLY=( $(compgen -W "${projects}" -- ${cur}) ) | |
elif [[ $COMP_CWORD -gt 1 ]]; then | |
if [[ ${COMP_WORDS[COMP_CWORD-2]} =~ (^| )(build|inspect|devkit)$ ]]; then | |
# complete platforms | |
COMPREPLY=( $(compgen -W "${platforms}" -- ${cur}) ) | |
fi | |
fi | |
fi | |
return 0 | |
} | |
complete -F _vanagon_actions be | |
complete -F _vanagon_actions bundle | |
# ex: filetype=sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment