From: Fedyashev Nikita Date: Fri, 19 Nov 2010 05:22:13 +0000 (-0500) Subject: refactored version; valid workflow X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=5f6125e480267a2bcd52827f4430b7cec2ab35df;p=common%2Fbash_it.git refactored version; valid workflow --- diff --git a/plugins/vagrant.plugins.bash b/plugins/vagrant.plugins.bash index 3d05f7e..27b3761 100644 --- a/plugins/vagrant.plugins.bash +++ b/plugins/vagrant.plugins.bash @@ -1,34 +1,44 @@ #!/bin/bash _vagrant() { - local cur prev commands - COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" 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 - "remove"|"repackage") - #local vagrantlist=$(gem list -l|grep '([0-9].*)'|awk 'BEGIN {ORS=" "} { print $1}'|sort) - #local vagrantlist=$(command ls --color=none -l $HOME/.vagrant/boxes 2>/dev/null | sed -e 's/ /\\ /g' | awk 'BEGIN {ORS=" "} {print $2}' ) - local vagrantlist=$(find $HOME/.vagrant/boxes/* -maxdepth 0 -type d -printf '%f ') - COMPREPLY=($(compgen -W "${vagrantlist}" -- ${cur})) - return 0 - ;; - "box") - commands="add help list remove repackage" - COMPREPLY=($(compgen -W "${commands}" -- ${cur})) - return 0 - ;; - *) - ;; - esac + if [ $COMP_CWORD == 1 ] + then + commands="box destroy halt help init package provision reload resume ssh ssh_config status suspend up version" + COMPREPLY=($(compgen -W "${commands}" -- ${cur})) + return 0 + fi + + if [ $COMP_CWORD == 2 ] + then + if [ $prev == 'box' ] + then + commands="add help list remove repackage" + COMPREPLY=($(compgen -W "${commands}" -- ${cur})) + return 0 + fi + 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-e