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
2010-05-30 13:00:51 -07:00
local cellar_contents formulae
2009-07-28 01:45:17 -07:00
COMPREPLY = ( )
cur = " ${ COMP_WORDS [COMP_CWORD] } "
2010-05-30 13:00:51 -07:00
# We usually only complete unabbreviated commands.
2010-06-09 20:57:10 -07:00
actions = "--cache --config --prefix cat cleanup configure create deps doctor edit home info install link list log outdated prune remove search unlink update uses"
2010-05-30 13:00:51 -07:00
if [ [ ( ${ COMP_CWORD } -eq 1 ) && ( ${ COMP_WORDS [0] } = = brew ) ] ] ; then
# Subcommand list.
2009-07-28 01:45:17 -07:00
COMPREPLY = ( $( compgen -W " ${ actions } " -- ${ cur } ) )
return 0
else
2010-05-30 13:00:51 -07:00
# Find the previous non-switch word
2010-02-27 16:51:12 -08:00
prev_index = $(( COMP_CWORD - 1 ))
prev = " ${ COMP_WORDS [prev_index] } "
2010-05-30 13:00:51 -07:00
while [ [ $prev = = -* ] ] ; do
2010-02-27 16:51:12 -08:00
prev_index = $(( prev_index - 1 ))
prev = " ${ COMP_WORDS [prev_index] } "
done
2010-05-30 13:00:51 -07:00
2009-07-31 09:45:04 -07:00
case ${ prev } in
2010-05-30 13:00:51 -07:00
# Commands that take a formula.
cat| deps| edit| home| homepage| info| install| log| uses)
formulae = $( ls $( brew --repository) /Library/Formula/ | sed "s/\.rb//g" )
2009-07-31 09:45:04 -07:00
COMPREPLY = ( $( compgen -W " ${ formulae } " -- ${ cur } ) )
return 0
; ;
2010-05-30 13:00:51 -07:00
# Commands that take an existing brew.
abv| cleanup| link| list| ln| ls| remove| rm| uninstall| unlink)
cellar_contents = $( ls $( brew --cellar) )
2009-07-31 09:45:04 -07:00
COMPREPLY = ( $( compgen -W " ${ cellar_contents } " -- ${ cur } ) )
return 0
; ;
2010-05-30 13:00:51 -07:00
2009-07-31 09:45:04 -07:00
esac
2009-07-28 01:45:17 -07:00
fi
}
complete -F _brew_to_completion brew