1 # brew-completion: bash completion function for Homebrew (brew command)
2 # Copyright (c)2010 Alexander Barton <alex@barton.de>
3 # This is free software and published under the terms of the GNU
4 # General Public License, see the file COPYING for details.
10 prefix=`brew --prefix`
11 formulae=`brew search`
12 COMPREPLY=( $(compgen -W '$formulae' -- "$1") )
15 _brew_formula_installed()
19 prefix=`brew --prefix`
21 COMPREPLY=( $(compgen -W '$formulae' -- "$1") )
30 prev=${COMP_WORDS[COMP_CWORD-1]}
33 # Get list of all available external commands
34 extcmdpath="`brew --prefix`/Library/Homebrew/cmd";
35 if [ -d "$extcmdpath" ]; then
36 EXTCMD="$EXTCMD `cd "$extcmdpath"; ls -1 -- *.rb 2>/dev/null \
39 examplespath="`brew --prefix`/Library/Contributions/examples"
40 if [ -d "$examplespath" ]; then
41 EXTCMD="$EXTCMD `cd "$examplespath"; ls -1 -- brew-* 2>/dev/null \
42 | cut -d'.' -f1 | cut -d'-' -f2- | sed -e 's/\*//g'`"
45 declare -i i=$COMP_CWORD-1
46 while [ $i -gt 0 ]; do
47 if [[ ${COMP_WORDS[i]} != -* \
48 || ${COMP_WORDS[i]} == "--cache" \
49 || ${COMP_WORDS[i]} == "--cellar" \
50 || ${COMP_WORDS[i]} == "--config" \
51 || ${COMP_WORDS[i]} == "--prefix" ]]; then
59 "cat"|"cleanup"|"deps"|"edit"|"home"|"log"|"prune"|"uses" \
60 |"--cache"|"--cellar"|"--prefix")
64 "link"|"remove"|"rm"|"uninstall"|"unlink")
65 _brew_formula_installed "$cur"
69 if [[ "$cur" == -* ]]; then
70 COMPREPLY=( $(compgen -W '--macports --fink \
76 if [[ "$cur" == -* ]]; then
77 COMPREPLY=( $(compgen -W '--all --github' \
85 if [[ "$cur" == -* ]]; then
86 COMPREPLY=( $(compgen -W '--git --HEAD -H \
87 --debug -d --force -f \
88 --interactive -i --verbose -v \
89 --ignore-dependencies --use-llvm' \
97 if [[ "$cur" == -* ]]; then
98 COMPREPLY=( $(compgen -W '
99 --unbrewed' -- "$cur") )
107 if [ "$cmd" = "$c" ]; then
114 if [[ "$cur" == -* ]]; then
115 COMPREPLY=( $(compgen -W '--cache --cellar --config \
116 --env --help --prefix --version -v -H' \
118 elif [ "$cmd" = "" ]; then
119 COMPREPLY=( $(compgen -W 'cat cleanup create deps doctor \
120 edit home info install link list log outdated prune \
121 remove rm search uninstall unlink up update uses \
126 complete -F _brew brew