Created
April 14, 2012 13:16
-
-
Save OleMchls/2384354 to your computer and use it in GitHub Desktop.
Vagrant bash autocomplete
This file contains hidden or 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
# Autocompletion for Vagrant just put this line in your ~/.profile | |
complete -W "$(echo `vagrant --help | awk '/box/,/up/ {print $1}'`;)" vagrant |
@Velaa98 There's a possibility you have a plugin installed which provides a vagrant command with the string "up" in its name, for example something like vagrant-hostsupdater. If this is the case then you might be getting a shorter command list from vagrant list-commands | awk '/box/,/up/ {print $1}'
than you were expecting.
I saw a comment on stackoverflow that made me think this might work:
# Vagrant bash completion.
complete -W "$(echo $(vagrant list-commands | sed '1,3d' | awk '{print $1}'))" vagrant
As far as I understand it...
- We use the
complete
bash builtin function, pass it a word list-W "..."
and tell it to do its magic on thevagrant
command. - The word list is constructed by using two nested command substitions -
$()
- "it literally plugs the command output into another context". - The outermost command substitution
echo
will print the results of the innermost onevagrant list-commands | sed '1,3d' | awk '{print $1}
. vagrant list-commands
will give us a list of commands vagrant knows about, but with 3 lines of descriptive text at the start.- The
sed
command1,3d
will delete the first 3 lines of the output piped to it, this is how the header text is chopped off. - The
awk
program{print $1}
prints the first field for each line of output. A field toawk
is anything up to the first white-space character for each line, this is how the descriptions are removed, leaving just thevagrant
command name.
I think that's how it works.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good contribution, thanks. I tried replacing "--help" with "list-commands" but the "rsync" option does not appear. You know why?