Contribution: Tweak bash completion for install

Selection of generic installation options, such as `--HEAD`, is now lumped
together with selection of formulae-specific options.

This allows any installation option to be tab-completed *before or after* the
formula name is specified.

Signed-off-by: Adam Vandenberg <flangy@gmail.com>
This commit is contained in:
Charlie Sharpsteen 2011-08-17 22:43:57 -07:00 committed by Adam Vandenberg
parent df113d3ce6
commit 8a1bcf70a1

View File

@ -26,13 +26,13 @@ _brew_to_completion()
prev="${COMP_WORDS[prev_index]}" prev="${COMP_WORDS[prev_index]}"
done done
case "$prev" in # Handle installation --options
# Commands that take a formula if [[ ${COMP_WORDS[1]} == "install" && "$cur" == --* ]]; then
cat|deps|edit|fetch|home|homepage|info|install|log|missing|options|uses|versions)
# handle standard --options
if [[ "$prev" == "install" && "$cur" == --* ]]; then
local opts=$( local opts=$(
local opts=( --force --verbose --debug --use-clang --use-gcc --use-llvm --ignore-dependencies --HEAD ) local opts=(
--force --verbose --debug --use-clang --use-gcc --use-llvm --ignore-dependencies --HEAD
$(brew options --compact "$prev")
)
for o in ${opts[*]}; do for o in ${opts[*]}; do
[[ " ${COMP_WORDS[*]} " =~ " $o " ]] || echo "$o" [[ " ${COMP_WORDS[*]} " =~ " $o " ]] || echo "$o"
done done
@ -40,6 +40,10 @@ _brew_to_completion()
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
return return
fi fi
case "$prev" 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 | sed "s/\.rb//g") 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") local af=$(\ls $(brew --repository)/Library/Aliases 2> /dev/null | sed "s/\.rb//g")
COMPREPLY=( $(compgen -W "${ff} ${af}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${ff} ${af}" -- ${cur}) )
@ -50,19 +54,6 @@ _brew_to_completion()
COMPREPLY=( $(compgen -W "$(\ls $(brew --cellar))" -- ${cur}) ) COMPREPLY=( $(compgen -W "$(\ls $(brew --cellar))" -- ${cur}) )
return return
;; ;;
# Complete --options for selected brew
*)
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 esac
} }