fix problems with brew completion
- update plugin architecture
- completion function in $ZSH/functions/brew
- plugins/brew.plugin.zsh only activates
Diff
1diff --git a/functions/brew/_brew b/functions/brew/_brew
2new file mode 100644
3index 0000000000000000000000000000000000000000..4e590ac6302d0196a9b269798ea9f4ded913a05c
4--- /dev/null
5+++ b/functions/brew/_brew
6@@ -0,0 +1,69 @@
7+#compdef brew
8+#autoload
9+
10+# imported from the latest homebrew contributions
11+
12+_brew_all_formulae() {
13+ formulae=(`brew search`)
14+}
15+
16+_brew_installed_formulae() {
17+ installed_formulae=(`brew list`)
18+}
19+
20+local -a _1st_arguments
21+_1st_arguments=(
22+ 'cat:display formula file for a formula'
23+ 'cleanup:uninstall unused and old versions of packages'
24+ 'create:create a new formula'
25+ 'deps:list dependencies and dependants of a formula'
26+ 'doctor:audits your installation for common issues'
27+ 'edit:edit a formula'
28+ 'home:visit the homepage of a formula or the brew project'
29+ 'info:information about a formula'
30+ 'install:install a formula'
31+ 'link:link a formula'
32+ 'list:list files in a formula or not-installed formulae'
33+ 'log:git commit log for a formula'
34+ 'outdated:list formulas for which a newer version is available'
35+ 'prune:remove dead links'
36+ 'remove:remove a formula'
37+ 'search:search for a formula (/regex/ or string)'
38+ 'unlink:unlink a formula'
39+ 'update:freshen up links'
40+ 'uses:show formulas which depend on a formula'
41+)
42+
43+local expl
44+local -a formula installed_formulae
45+
46+_arguments \
47+ '(-v --verbose)'{-v,--verbose}'[verbose]' \
48+ '(--version)--version[version information]' \
49+ '(--prefix)--prefix[where brew lives on this system]' \
50+ '(--cache)--cache[brew cache]' \
51+ '*:: :->subcmds' && return 0
52+
53+if (( CURRENT == 1 )); then
54+ _describe -t commands "brew subcommand" _1st_arguments
55+ return
56+fi
57+
58+case "$words[1]" in
59+ list)
60+ _arguments \
61+ '(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \
62+ '1: :->forms' && return 0
63+
64+ if [[ "$state" == forms ]]; then
65+ _brew_installed_formulae
66+ _requested installed_formulae expl 'installed formulae' compadd -a installed_formulae
67+ fi ;;
68+ install|home|log|info|uses|cat|deps)
69+ _brew_all_formulae
70+ _wanted formulae expl 'all formulae' compadd -a formulae ;;
71+ remove|edit|xo)
72+ _brew_installed_formulae
73+ _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;;
74+esac
75+
76diff --git a/plugins/brew.plugin.zsh b/plugins/brew.plugin.zsh
77index 162eb6442351855f82e0d0bf89e433ace7f4fe1e..a30540966bd64b8eb24c9d87f0ba31f3a0fc1ab2 100644
78--- a/plugins/brew.plugin.zsh
79+++ b/plugins/brew.plugin.zsh
80@@ -1,67 +1,4 @@
81-#compdef brew
82-
83-# imported from the latest homebrew contributions
84-
85-_brew_all_formulae() {
86- formulae=(`brew search`)
87-}
88-
89-_brew_installed_formulae() {
90- installed_formulae=(`brew list`)
91-}
92-
93-local -a _1st_arguments
94-_1st_arguments=(
95- 'cat:display formula file for a formula'
96- 'cleanup:uninstall unused and old versions of packages'
97- 'create:create a new formula'
98- 'deps:list dependencies and dependants of a formula'
99- 'doctor:audits your installation for common issues'
100- 'edit:edit a formula'
101- 'home:visit the homepage of a formula or the brew project'
102- 'info:information about a formula'
103- 'install:install a formula'
104- 'link:link a formula'
105- 'list:list files in a formula or not-installed formulae'
106- 'log:git commit log for a formula'
107- 'outdated:list formulas for which a newer version is available'
108- 'prune:remove dead links'
109- 'remove:remove a formula'
110- 'search:search for a formula (/regex/ or string)'
111- 'unlink:unlink a formula'
112- 'update:freshen up links'
113- 'uses:show formulas which depend on a formula'
114-)
115-
116-local expl
117-local -a formula installed_formulae
118-
119-_arguments \
120- '(-v --verbose)'{-v,--verbose}'[verbose]' \
121- '(--version)--version[version information]' \
122- '(--prefix)--prefix[where brew lives on this system]' \
123- '(--cache)--cache[brew cache]' \
124- '*:: :->subcmds' && return 0
125-
126-if (( CURRENT == 1 )); then
127- _describe -t commands "brew subcommand" _1st_arguments
128- return
129-fi
130-
131-case "$words[1]" in
132- list)
133- _arguments \
134- '(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \
135- '1: :->forms' && return 0
136-
137- if [[ "$state" == forms ]]; then
138- _brew_installed_formulae
139- _requested installed_formulae expl 'installed formulae' compadd -a installed_formulae
140- fi ;;
141- install|home|log|info|uses|cat|deps)
142- _brew_all_formulae
143- _wanted formulae expl 'all formulae' compadd -a formulae ;;
144- remove|edit|xo)
145- _brew_installed_formulae
146- _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;;
147-esac
148+# add brew completion function to path
149+fpath=($ZSH/functions/brew $fpath)
150+autoload -U compinit
151+compinit -i