From e4bed29e99a2fb7be5b2c175f5d38d1cb294ef92 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 11 Dec 2011 01:29:15 -0600 Subject: 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 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 --- Library/Contributions/brew_bash_completion.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Library/Contributions/brew_bash_completion.sh b/Library/Contributions/brew_bash_completion.sh index 028920471..97b379190 100644 --- a/Library/Contributions/brew_bash_completion.sh +++ b/Library/Contributions/brew_bash_completion.sh @@ -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") -- cgit v1.2.3