2010-07-19 09:51:28 -07:00
|
|
|
# Bash completion script for brew(1)
|
2009-09-05 20:47:15 +01:00
|
|
|
#
|
2010-07-19 09:51:28 -07:00
|
|
|
# To use, edit your .bashrc and add:
|
2009-07-31 22:10:50 -07:00
|
|
|
# source `brew --prefix`/Library/Contributions/brew_bash_completion.sh
|
2009-07-31 09:45:04 -07:00
|
|
|
|
2009-07-28 01:45:17 -07:00
|
|
|
_brew_to_completion()
|
|
|
|
{
|
2010-07-19 09:51:28 -07:00
|
|
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
|
|
|
|
# Subcommand list
|
|
|
|
[[ ${COMP_CWORD} -eq 1 ]] && {
|
2011-05-04 20:35:56 -05:00
|
|
|
local actions="--cache --cellar --config --env --prefix --repository audit cat cleanup
|
|
|
|
configure create deps doctor edit fetch help home info install link list log options
|
2011-08-28 14:12:32 -05:00
|
|
|
outdated prune remove search test uninstall unlink update upgrade uses versions"
|
2010-10-01 07:07:46 -07:00
|
|
|
local ext=$(\ls $(brew --repository)/Library/Contributions/examples |
|
2010-07-19 09:51:28 -07:00
|
|
|
sed -e "s/\.rb//g" -e "s/brew-//g")
|
|
|
|
COMPREPLY=( $(compgen -W "${actions} ${ext}" -- ${cur}) )
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
# Find the previous non-switch word
|
|
|
|
local prev_index=$((COMP_CWORD - 1))
|
|
|
|
local prev="${COMP_WORDS[prev_index]}"
|
|
|
|
while [[ $prev == -* ]]; do
|
|
|
|
prev_index=$((--prev_index))
|
2010-02-27 16:51:12 -08:00
|
|
|
prev="${COMP_WORDS[prev_index]}"
|
2010-07-19 09:51:28 -07:00
|
|
|
done
|
|
|
|
|
2011-08-17 22:43:57 -07:00
|
|
|
# Handle installation --options
|
|
|
|
if [[ ${COMP_WORDS[1]} == "install" && "$cur" == --* ]]; then
|
|
|
|
local opts=$(
|
|
|
|
local opts=(
|
2011-08-25 00:08:30 -05:00
|
|
|
--force --verbose --debug --use-clang --use-gcc --use-llvm --ignore-dependencies --build-from-source --HEAD
|
2011-08-17 22:43:57 -07:00
|
|
|
$(brew options --compact "$prev")
|
|
|
|
)
|
|
|
|
for o in ${opts[*]}; do
|
|
|
|
[[ " ${COMP_WORDS[*]} " =~ " $o " ]] || echo "$o"
|
|
|
|
done
|
|
|
|
)
|
|
|
|
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2010-07-19 09:51:28 -07:00
|
|
|
case "$prev" in
|
|
|
|
# Commands that take a formula
|
2010-10-27 10:03:30 +02:00
|
|
|
cat|deps|edit|fetch|home|homepage|info|install|log|missing|options|uses|versions)
|
2010-10-01 07:07:46 -07:00
|
|
|
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")
|
2010-07-19 09:51:28 -07:00
|
|
|
COMPREPLY=( $(compgen -W "${ff} ${af}" -- ${cur}) )
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
# Commands that take an existing brew
|
2011-08-28 14:12:32 -05:00
|
|
|
abv|cleanup|link|list|ln|ls|remove|rm|test|upgrade|uninstall|unlink)
|
2010-10-01 07:07:46 -07:00
|
|
|
COMPREPLY=( $(compgen -W "$(\ls $(brew --cellar))" -- ${cur}) )
|
2010-07-19 09:51:28 -07:00
|
|
|
return
|
|
|
|
;;
|
|
|
|
esac
|
2009-07-28 01:45:17 -07:00
|
|
|
}
|
|
|
|
|
2010-07-19 09:51:28 -07:00
|
|
|
complete -o bashdefault -o default -F _brew_to_completion brew
|