Skip to content

Instantly share code, notes, and snippets.

@drscream
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save drscream/48e2bff4198a5db0ad28 to your computer and use it in GitHub Desktop.

Select an option

Save drscream/48e2bff4198a5db0ad28 to your computer and use it in GitHub Desktop.
Place it in ~/.bash_completion.d
# debian, ubuntu do not support user generated bash_completion.d
# refs:
# - http://www.debian-administration.org/articles/316
# - http://www.debian-administration.org/article/An_introduction_to_bash_completion_part_2
DIR="${HOME}/.bash_completion.d"
# source completion directory definitions
if [ -d $DIR -a -r $DIR -a -x $DIR ]; then
for i in $DIR/*; do
[ \( -f $i -o -h $i \) -a -r $i ] && . $i
done
fi
unset i
unset DIR
# deploy-zone - bash completion
# https://github.com/wiedi/deploy-zone
# Thomas Merkel <[email protected]>
_dz() {
local cur prev
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case ${prev} in
shell|start|stop)
local uuid=$( cat ~/.dz/vms.json | jq -r '.[][].uuid' )
COMPREPLY=( $(compgen -W "${uuid}" -- ${cur}) )
;;
list)
local options=$( dz list --help | grep "^ " | awk -F'[,]' '{ print $1 }' )
COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
;;
*)
local commands=$( dz --help | grep "^ " | awk '{ print $1 }' )
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
;;
esac
}
complete -F _dz dz
# vim:ft=sh:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment