Added basic support for bash autocompletion #882

Merged
merged 2 commits into from May 5, 2012

4 participants

@nesQuick

At the moment it's based on the first and last command in the help list. When they change this script wont work properly anymore. But for me this is very helpful.

@mlafeldt

Hi,

I would rather make it independent of the actual commands to be future-proof. Something like:

$ vagrant --help | awk '/^     /{print $1}'
box
destroy
gem
halt
init
package
provision
reload
resume
ssh
ssh-config
status
suspend
up

And what is the echo good for?

@nesQuick

Honestly I'm not sure if trusting on the amount of spaces is really more future proof, but I changed the commit and crossed my finger that this won't change that fast.

The echo is there for.. ehm. I just don't know but without it it just wont work :D

@mitchellh
Owner

Looks good 👍 Thanks! Merged.

@mitchellh mitchellh merged commit b7b4307 into mitchellh:master May 5, 2012
@nesQuick

👍

@l0b0

@nesQuick I suspect echo is simply used to make the arguments space separated rather than newline separated. This can also be done with

vagrant --help | awk '/^     /{printf "%s ", $1}' # Creates an extra space at the end, which may be an issue

or

vagrant --help | awk '/^     /{print $1}' | tr '\n' ' ' # Very likely slower than echo

However, for me this works:

complete -W "$(vagrant --help | awk '/^     /{print $1}')" vagrant

While this does not (only completes as box):

complete -W $(vagrant --help | awk '/^     /{print $1}') vagrant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment