Merge pull request #2329 from pstadler/brew-cask
add brew-cask plugin
Diff
1diff --git a/plugins/brew-cask/brew-cask.plugin.zsh b/plugins/brew-cask/brew-cask.plugin.zsh
2new file mode 100644
3index 0000000000000000000000000000000000000000..91ce0f49816ca34fe566895fc5a8c217f2009224
4--- /dev/null
5+++ b/plugins/brew-cask/brew-cask.plugin.zsh
6@@ -0,0 +1,84 @@
7+# Autocompletion for homebrew-cask.
8+#
9+# This script intercepts calls to the brew plugin and adds autocompletion
10+# for the cask subcommand.
11+#
12+# Author: https://github.com/pstadler
13+
14+compdef _brew-cask brew
15+
16+_brew-cask()
17+{
18+ local curcontext="$curcontext" state line
19+ typeset -A opt_args
20+
21+ _arguments -C \
22+ ':command:->command' \
23+ ':subcmd:->subcmd' \
24+ '*::options:->options'
25+
26+ case $state in
27+ (command)
28+ __call_original_brew
29+ cask_commands=(
30+ 'cask:manage casks'
31+ )
32+ _describe -t commands 'brew cask command' cask_commands ;;
33+
34+ (subcmd)
35+ case "$line[1]" in
36+ cask)
37+ if (( CURRENT == 3 )); then
38+ local -a subcommands
39+ subcommands=(
40+ "alfred:used to modify Alfred's scope to include the Caskroom"
41+ 'audit:verifies installability of casks'
42+ 'checklinks:checks for bad cask links'
43+ 'cleanup:cleans up cached downloads'
44+ 'create:creates a cask of the given name and opens it in an editor'
45+ 'doctor:checks for configuration issues'
46+ 'edit:edits the cask of the given name'
47+ 'fetch:downloads Cask resources to local cache'
48+ 'home:opens the homepage of the cask of the given name'
49+ 'info:displays information about the cask of the given name'
50+ 'install:installs the cask of the given name'
51+ 'list:with no args, lists installed casks; given installed casks, lists installed files'
52+ 'search:searches all known casks'
53+ 'uninstall:uninstalls the cask of the given name'
54+ "update:a synonym for 'brew update'"
55+ )
56+ _describe -t commands "brew cask subcommand" subcommands
57+ fi ;;
58+
59+ *)
60+ __call_original_brew ;;
61+ esac ;;
62+
63+ (options)
64+ local -a casks installed_casks
65+ local expl
66+ case "$line[2]" in
67+ list|uninstall)
68+ __brew_installed_casks
69+ _wanted installed_casks expl 'installed casks' compadd -a installed_casks ;;
70+ audit|edit|home|info|install)
71+ __brew_all_casks
72+ _wanted casks expl 'all casks' compadd -a casks ;;
73+ esac ;;
74+ esac
75+}
76+
77+__brew_all_casks() {
78+ casks=(`brew cask search`)
79+}
80+
81+__brew_installed_casks() {
82+ installed_casks=(`brew cask list`)
83+}
84+
85+__call_original_brew()
86+{
87+ local ret=1
88+ _call_function ret _brew
89+ compdef _brew-cask brew
90+}