refactored version; valid workflow

pull/26/head
Fedyashev Nikita 2010-11-19 00:22:13 -05:00
parent 4350c3f13f
commit 5f6125e480
1 changed files with 33 additions and 23 deletions

View File

@ -1,34 +1,44 @@
#!/bin/bash #!/bin/bash
_vagrant() _vagrant()
{ {
local cur prev commands
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
# The commands we will complete
commands="box destroy halt help init package provision reload resume ssh ssh_config status suspend up version"
case "${prev}" in if [ $COMP_CWORD == 1 ]
"remove"|"repackage") then
#local vagrantlist=$(gem list -l|grep '([0-9].*)'|awk 'BEGIN {ORS=" "} { print $1}'|sort) commands="box destroy halt help init package provision reload resume ssh ssh_config status suspend up version"
#local vagrantlist=$(command ls --color=none -l $HOME/.vagrant/boxes 2>/dev/null | sed -e 's/ /\\ /g' | awk 'BEGIN {ORS=" "} {print $2}' ) COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
local vagrantlist=$(find $HOME/.vagrant/boxes/* -maxdepth 0 -type d -printf '%f ') return 0
COMPREPLY=($(compgen -W "${vagrantlist}" -- ${cur})) fi
return 0
;; if [ $COMP_CWORD == 2 ]
"box") then
commands="add help list remove repackage" if [ $prev == 'box' ]
COMPREPLY=($(compgen -W "${commands}" -- ${cur})) then
return 0 commands="add help list remove repackage"
;; COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
*) return 0
;; fi
esac fi
if [ $COMP_CWORD == 3 ]
then
action="${COMP_WORDS[COMP_CWORD-2]}"
if [ $action == 'box' ]
then
case "$prev" in
"remove"|"repackage")
local vagrantlist=$(find $HOME/.vagrant/boxes/* -maxdepth 0 -type d -printf '%f ')
COMPREPLY=($(compgen -W "${vagrantlist}" -- ${cur}))
return 0
;;
*)
;;
esac
fi
fi
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
return 0
} }
complete -F _vagrant vagrant complete -F _vagrant vagrant
complete -F _vagrant vagrant-e