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