From c6e78260e740821b75d826132cb11357ff63130b Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sat, 5 Feb 2011 09:33:49 -0500 Subject: [PATCH] Handle default install --options i.e. `--force --debug --use-llvm --ignore-dependencies --HEAD` Additionally: * Use a cleaner `if` block in install options completion case. * De-dupe options for subsequent completion (e.g. stop offering --foo once --foo option has been used). Signed-off-by: Adam Vandenberg --- Library/Contributions/brew_bash_completion.sh | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Library/Contributions/brew_bash_completion.sh b/Library/Contributions/brew_bash_completion.sh index 6fc3465f20..d219bd5184 100644 --- a/Library/Contributions/brew_bash_completion.sh +++ b/Library/Contributions/brew_bash_completion.sh @@ -29,6 +29,17 @@ _brew_to_completion() case "$prev" in # Commands that take a formula cat|deps|edit|fetch|home|homepage|info|install|log|options|uses) + # handle standard --options + if [[ "$prev" == "install" && "$cur" == --* ]]; then + local opts=$( + local opts=( --force --debug --use-llvm --ignore-dependencies --HEAD ) + for o in ${opts[*]}; do + [[ " ${COMP_WORDS[*]} " =~ " $o " ]] || echo "$o" + done + ) + COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) + return + fi local ff=$(\ls $(brew --repository)/Library/Formula | sed "s/\.rb//g") local af=$(\ls $(brew --repository)/Library/Aliases 2> /dev/null | sed "s/\.rb//g") COMPREPLY=( $(compgen -W "${ff} ${af}" -- ${cur}) ) @@ -41,10 +52,16 @@ _brew_to_completion() ;; # Complete --options for selected brew *) - [[ ${COMP_WORDS[1]} == "install" ]] && [[ "$cur" == --* ]] && { - COMPREPLY=( $(compgen -W "$(brew options --compact "$prev")" -- ${cur}) ) + if [[ ${COMP_WORDS[1]} == "install" && "$cur" == --* ]]; then + local opts=$( + local opts=( $(brew options --compact "$prev") ) + for o in ${opts[*]}; do + [[ " ${COMP_WORDS[*]} " =~ " $o " ]] || echo "$o" + done + ) + COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) return - } + fi ;; esac }