From 898bff4442f579d34ce6f54334ab5d733f3c9001 Mon Sep 17 00:00:00 2001 From: Eugene Kalinin Date: Fri, 24 May 2013 13:45:44 +0400 Subject: [PATCH] Improved autocompletion for bash --- contrib/bash/completion.sh | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/contrib/bash/completion.sh b/contrib/bash/completion.sh index 40d12d3fb00..fb6fc508ab6 100644 --- a/contrib/bash/completion.sh +++ b/contrib/bash/completion.sh @@ -1,3 +1,31 @@ # Autocompletion for Vagrant just put this line in your ~/.profile or link this file into it like: # source /path/to/vagrant/contrib/bash/completion.sh -complete -W "$(echo `vagrant --help | awk '/^ /{print $1}'`;)" vagrant +_vagrant() { + + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + preprev="${COMP_WORDS[COMP_CWORD-2]}" + + commands=$(vagrant --help | awk '/^ /{print $1}') + + if [ $COMP_CWORD == 1 ] ; then + COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) ) + return 0 + fi + + if [ $COMP_CWORD == 2 ] ; then + local sub_commands=$(vagrant $prev --help | awk '/^ /{print $1}') + COMPREPLY=( $(compgen -W "${sub_commands}" -- ${cur}) ) + return 0 + fi + + if [[ ${cur} == -* ]] ; then + local command_opts=$(vagrant $preprev $prev --help | grep -E -o "((-\w{1}|--(\w|-)*=?)){1,2}") + COMPREPLY=( $(compgen -W "${command_opts}" -- ${cur}) ) + return 0 + fi +} + +complete -F _vagrant vagrant + +# /* vim: set filetype=sh : */