forked from hashicorp/vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hashicorp#1763 from ekalinin/patch-1
Improved autocompletion for bash
- Loading branch information
Showing
1 changed file
with
29 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 : */ |