completion: complete multiple formula arguments

We make the assumption that the first non-option word is the command
being invoked.

Originally I was trying to allow command completion for non-standard
command lines like

    $ brew --verbose inst<TAB>

but right now executing something like that doesn't actually work. Which
is interesting, because the man page implies that it should. Either the
man page is incorrect, or something was broken between then and now.

Anyway, it would probably be safe to just assume that COMP_WORDS[1] is
the command, and we do make that assumption in other places. But if we
ever do allow things like "brew --option command", this will be useful.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
Jack Nagel 2011-12-11 01:29:15 -06:00
parent ca7b7fb4f1
commit e4bed29e99

View File

@ -205,7 +205,14 @@ _brew_to_completion()
esac
fi
case "$prev" in
# find the index of the *first* non-switch word
# we can use this to allow completion for multiple formula arguments
local cmd_index=1
while [[ ${COMP_WORDS[cmd_index]} == -* ]]; do
cmd_index=$((++cmd_index))
done
case "${COMP_WORDS[cmd_index]}" in
# Commands that take a formula
cat|deps|edit|fetch|home|homepage|info|install|log|missing|options|uses|versions)
local ff=$(\ls $(brew --repository)/Library/Formula 2> /dev/null | sed "s/\.rb//g")