Skip to content

Commit f4782c0

Browse files
author
mdelage
committed
add _brew
1 parent e69d4ff commit f4782c0

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

_brew

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#compdef brew
2+
#autoload
3+
4+
# Brew ZSH completion function
5+
# Drop this somewhere in your $fpath (like /usr/share/zsh/site-functions)
6+
# and rename it _brew
7+
#
8+
# altered from _fink
9+
10+
_brew_all_formulae() {
11+
formulae=(`brew search`)
12+
}
13+
14+
_brew_installed_formulae() {
15+
installed_formulae=(`brew list`)
16+
}
17+
18+
_brew_installed_taps() {
19+
installed_taps=(`brew tap`)
20+
}
21+
22+
_brew_official_taps() {
23+
official_taps=(`brew tap --list-official`)
24+
}
25+
26+
_brew_pinned_taps() {
27+
pinned_taps=(`brew tap --list-pinned`)
28+
}
29+
30+
_brew_outdated_formulae() {
31+
outdated_formulae=(`brew outdated`)
32+
}
33+
34+
local -a _1st_arguments
35+
_1st_arguments=(
36+
'audit:check formulae for Homebrew coding style'
37+
'cat:display formula file for a formula'
38+
'cleanup:uninstall unused and old versions of packages'
39+
'commands:show a list of commands'
40+
'config:show homebrew and system configuration'
41+
'create:create a new formula'
42+
'deps:list dependencies and dependants of a formula'
43+
'desc:display a description of a formula'
44+
'doctor:audits your installation for common issues'
45+
'edit:edit a formula'
46+
'fetch:download formula resources to the cache'
47+
'gist-logs:generate a gist of the full build logs'
48+
'home:visit the homepage of a formula or the brew project'
49+
'info:information about a formula'
50+
'install:install a formula'
51+
'reinstall:install a formula anew; re-using its current options'
52+
'leaves:show installed formulae that are not dependencies of another installed formula'
53+
'link:link a formula'
54+
'list:list files in a formula or not-installed formulae'
55+
'log:git commit log for a formula'
56+
'missing:check all installed formuale for missing dependencies.'
57+
'migrate:migrate renamed formula to new name'
58+
'outdated:list formulae for which a newer version is available'
59+
'pin:pin specified formulae'
60+
'postinstall:perform post_install for a given formula'
61+
'prune:remove dead links'
62+
'remove:remove a formula'
63+
'search:search for a formula (/regex/ or string)'
64+
'switch:switch between different versions of a formula'
65+
'tap:tap a new formula repository from GitHub, or list existing taps'
66+
'tap-info:information about a tap'
67+
'tap-pin:pin a tap'
68+
'tap-unpin:unpin a tap'
69+
'test-bot:test a formula and build a bottle'
70+
'uninstall:uninstall a formula'
71+
'unlink:unlink a formula'
72+
'unpin:unpin specified formulae'
73+
'untap:remove a tapped repository'
74+
'update:fetch latest version of Homebrew and all formulae'
75+
'upgrade:upgrade outdated formulae'
76+
'uses:show formulae which depend on a formula'
77+
`brew commands --quiet --include-aliases`
78+
)
79+
80+
local expl
81+
local -a formulae installed_formulae installed_taps official_taps outdated_formulae
82+
83+
_arguments \
84+
'(-v)-v[verbose]' \
85+
'(--cellar)--cellar[brew cellar]' \
86+
'(--env)--env[brew environment]' \
87+
'(--repository)--repository[brew repository]' \
88+
'(--version)--version[version information]' \
89+
'(--prefix)--prefix[where brew lives on this system]' \
90+
'(--cache)--cache[brew cache]' \
91+
'*:: :->subcmds' && return 0
92+
93+
if (( CURRENT == 1 )); then
94+
_describe -t commands "brew subcommand" _1st_arguments
95+
return
96+
fi
97+
98+
case "$words[1]" in
99+
install|reinstall|audit|home|homepage|log|info|abv|uses|cat|deps|desc|edit|options|switch)
100+
_brew_all_formulae
101+
_wanted formulae expl 'all formulae' compadd -a formulae ;;
102+
list|ls)
103+
_arguments \
104+
'(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \
105+
'(--pinned)--pinned[list all versions of pinned formulae]' \
106+
'(--versions)--versions[list all installed versions of a formula]' \
107+
'1: :->forms' && return 0
108+
109+
if [[ "$state" == forms ]]; then
110+
_brew_installed_formulae
111+
_wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae
112+
fi ;;
113+
remove|rm|uninstall|unlink|cleanup|link|ln|pin|unpin)
114+
_brew_installed_formulae
115+
_wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;;
116+
search|-S)
117+
_arguments \
118+
'(--macports)--macports[search the macports repository]' \
119+
'(--fink)--fink[search the fink repository]' ;;
120+
untap|tap-info|tap-pin)
121+
_brew_installed_taps
122+
_wanted installed_taps expl 'installed taps' compadd -a installed_taps ;;
123+
tap)
124+
_brew_official_taps
125+
_wanted official_taps expl 'official taps' compadd -a official_taps ;;
126+
tap-unpin)
127+
_brew_pinned_taps
128+
_wanted pinned_taps expl 'pinned taps' compadd -a pinned_taps ;;
129+
upgrade)
130+
_brew_outdated_formulae
131+
_wanted outdated_formulae expl 'outdated formulae' compadd -a outdated_formulae ;;
132+
esac

0 commit comments

Comments
 (0)