]> arthur.barton.de Git - brew-completion.git/blob - brew-completion.sh
Added support for brew command "--config"
[brew-completion.git] / brew-completion.sh
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.
5
6 _brew_formula()
7 {
8         local formulae prefix
9         
10         prefix=`brew --prefix`
11         formulae=`brew search`
12         COMPREPLY=( $(compgen -W '$formulae' -- "$1") )
13 }
14
15 _brew_formula_installed()
16 {
17         local formulae prefix
18         
19         prefix=`brew --prefix`
20         formulae=`brew list`
21         COMPREPLY=( $(compgen -W '$formulae' -- "$1") )
22 }
23
24 _brew()
25 {
26         local cur prev cmd i
27
28         COMPREPLY=()
29         cur=`_get_cword`
30         prev=${COMP_WORDS[COMP_CWORD-1]}
31         cmd=""
32
33         # Get list of all available external commands
34         EXTCMD=`cd /usr/local/bin; ls -1 brew-* | cut -d'.' -f1 \
35                 | cut -d'-' -f2- | sed -e 's/\*//g'`
36
37         declare -i i=$COMP_CWORD-1
38         while [ $i -gt 0 ]; do
39                 if [[ ${COMP_WORDS[i]} != -* \
40                    || ${COMP_WORDS[i]} == "--cache" \
41                    || ${COMP_WORDS[i]} == "--cellar" \
42                    || ${COMP_WORDS[i]} == "--config" \
43                    || ${COMP_WORDS[i]} == "--prefix" ]]; then
44                         cmd=${COMP_WORDS[i]}
45                         break
46                 fi
47                 i=$i-1
48         done
49
50         case "$cmd" in
51                 "cleanup"|"edit"|"home"|"log"|"prune" \
52                 |"--cache"|"--cellar"|"--prefix")
53                         _brew_formula "$cur"
54                         return 0
55                         ;;
56                 "link"|"remove"|"uninstall"|"unlink")
57                         _brew_formula_installed "$cur"
58                         return 0
59                         ;;
60                 "create")
61                         if [[ "$cur" == -* ]]; then
62                                 COMPREPLY=( $(compgen -W '--macports' \
63                                         -- "$cur") )
64                         fi
65                         return 0
66                         ;;
67                 "info")
68                         if [[ "$cur" == -* ]]; then
69                                 COMPREPLY=( $(compgen -W '--github' \
70                                         -- "$cur") )
71                         else
72                                 _brew_formula "$cur"
73                         fi
74                         return 0
75                         ;;
76                 "install")
77                         if [[ "$cur" == -* ]]; then
78                                 COMPREPLY=( $(compgen -W '--HEAD -H \
79                                         --debug -d --interactive -i
80                                         --verbose -v --ignore-dependencies' \
81                                         -- "$cur") )
82                         else
83                                 _brew_formula "$cur"
84                         fi
85                         return 0
86                         ;;
87                 "list")
88                         if [[ "$cur" == -* ]]; then
89                                 COMPREPLY=( $(compgen -W '
90                                         --unbrewed' -- "$cur") )
91                         else
92                                 _brew_formula "$cur"
93                         fi
94                         return 0
95                         ;;
96                 "search"|"update"|"--config")
97                         return 0
98                         ;;
99                 *)
100                         for c in $EXTCMD; do
101                                 if [ "$cmd" = "$c" ]; then
102                                         _brew_formula "$cur"
103                                         return 0
104                                 fi
105                         done
106         esac
107
108         if [[ "$cur" == -* ]]; then
109                 COMPREPLY=( $(compgen -W '--cache --cellar --config \
110                         --help --prefix --version -v -H' \
111                         -- "$cur") )
112         elif [ "$cmd" = "" ]; then
113                 COMPREPLY=( $(compgen -W 'cleanup create edit home info \
114                         install link list log outdated prune remove search \
115                         uninstall unlink update $EXTCMD' -- "$cur") )
116         fi
117 }
118 complete -F _brew brew