]> arthur.barton.de Git - brew-completion.git/blob - brew-completion.sh
Enable "brew {--cache|--cellar|--prefix}" to complete formula name
[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         declare -i i=$COMP_CWORD-1
34         while [ $i -gt 0 ]; do
35                 if [[ ${COMP_WORDS[i]} != -* \
36                    || ${COMP_WORDS[i]} == "--cache" \
37                    || ${COMP_WORDS[i]} == "--cellar" \
38                    || ${COMP_WORDS[i]} == "--prefix" ]]; then
39                         cmd=${COMP_WORDS[i]}
40                         break
41                 fi
42                 i=$i-1
43         done
44
45         case "$cmd" in
46                 "cleanup"|"edit"|"home"|"log"|"prune" \
47                 |"--cache"|"--cellar"|"--prefix")
48                         _brew_formula "$cur"
49                         return 0
50                         ;;
51                 "link"|"remove"|"uninstall"|"unlink")
52                         _brew_formula_installed "$cur"
53                         return 0
54                         ;;
55                 "create")
56                         if [[ "$cur" == -* ]]; then
57                                 COMPREPLY=( $(compgen -W '--macports' \
58                                         -- "$cur") )
59                         fi
60                         return 0
61                         ;;
62                 "info")
63                         if [[ "$cur" == -* ]]; then
64                                 COMPREPLY=( $(compgen -W '--github' \
65                                         -- "$cur") )
66                         else
67                                 _brew_formula "$cur"
68                         fi
69                         return 0
70                         ;;
71                 "install")
72                         if [[ "$cur" == -* ]]; then
73                                 COMPREPLY=( $(compgen -W '--HEAD -H \
74                                         --debug -d --interactive -i
75                                         --verbose -v --ignore-dependencies' \
76                                         -- "$cur") )
77                         else
78                                 _brew_formula "$cur"
79                         fi
80                         return 0
81                         ;;
82                 "list")
83                         if [[ "$cur" == -* ]]; then
84                                 COMPREPLY=( $(compgen -W '
85                                         --unbrewed' -- "$cur") )
86                         else
87                                 _brew_formula "$cur"
88                         fi
89                         return 0
90                         ;;
91                 "search"|"update")
92                         return 0
93                         ;;
94         esac
95
96         if [[ "$cur" == -* ]]; then
97                 COMPREPLY=( $(compgen -W '--cache --cellar --help --prefix \
98                         --version -v -H' -- "$cur") )
99         elif [ "$cmd" = "" ]; then
100                 COMPREPLY=( $(compgen -W 'cleanup create edit home info \
101                         install link list log outdated prune remove search \
102                         uninstall unlink update' -- "$cur") )
103         fi
104 }
105 complete -F _brew brew