2009-07-31 09:45:04 -07:00
|
|
|
# This script contains bash completions for brew.
|
2009-09-05 20:47:15 +01:00
|
|
|
#
|
2009-07-31 09:45:04 -07:00
|
|
|
# To use, edit your .bashrc and add the line:
|
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-02-27 16:51:12 -08:00
|
|
|
local actions cur prev prev_index
|
2009-07-28 01:45:17 -07:00
|
|
|
local cellar_contents formulae which_cellar brew_base
|
|
|
|
|
|
|
|
COMPREPLY=()
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
|
2009-07-31 09:45:04 -07:00
|
|
|
# We only complete unabbreviated commands...
|
2010-02-27 16:51:12 -08:00
|
|
|
actions="cat cleanup configure create deps edit generate homepage info install list link outdated prune remove search unlink update uses"
|
2009-07-28 01:45:17 -07:00
|
|
|
|
|
|
|
if [[ ( ${COMP_CWORD} -eq 1 ) && ( ${COMP_WORDS[0]} == brew ) ]] ; then
|
2010-02-27 16:51:12 -08:00
|
|
|
# Subcommand list
|
2009-07-28 01:45:17 -07:00
|
|
|
COMPREPLY=( $(compgen -W "${actions}" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
else
|
2010-02-27 16:51:12 -08:00
|
|
|
# Subcommands
|
2010-01-13 10:03:49 -08:00
|
|
|
brew_base=`brew --repository`
|
2009-07-28 01:45:17 -07:00
|
|
|
|
2010-02-27 16:51:12 -08:00
|
|
|
# We want the non-switch previous word
|
|
|
|
prev_index=$((COMP_CWORD - 1))
|
|
|
|
prev="${COMP_WORDS[prev_index]}"
|
|
|
|
while [[ $prev == -* ]]
|
|
|
|
do
|
|
|
|
prev_index=$((prev_index - 1))
|
|
|
|
prev="${COMP_WORDS[prev_index]}"
|
|
|
|
done
|
|
|
|
|
2009-07-31 09:45:04 -07:00
|
|
|
case ${prev} in
|
|
|
|
# Commands that take a formula...
|
2010-02-27 16:51:12 -08:00
|
|
|
cat|deps|edit|install|home|homepage|uses)
|
2009-07-31 09:45:04 -07:00
|
|
|
formulae=`ls ${brew_base}/Library/Formula/ | sed "s/\.rb//g"`
|
|
|
|
COMPREPLY=( $(compgen -W "${formulae}" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
# Commands that take an existing brew...
|
2010-01-18 08:30:29 +00:00
|
|
|
abv|cleanup|info|list|link|ls|ln|rm|remove|uninstall|unlink)
|
2009-07-31 09:45:04 -07:00
|
|
|
cellar_contents=`ls ${brew_base}/Cellar/`
|
|
|
|
COMPREPLY=( $(compgen -W "${cellar_contents}" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
2009-07-28 01:45:17 -07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
complete -F _brew_to_completion brew
|