288604ef1a19c5808eff439acf32330fda126f93

Author
Patrick Stadler <patrick.stadler@gmail.com>
Committer
Patrick Stadler <patrick.stadler@gmail.com>
Date

Message

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..ef4f5208d9838925bcbba31c518dbd0ef14753b2
 4--- /dev/null
 5+++ b/plugins/brew-cask/brew-cask.plugin.zsh
 6@@ -0,0 +1,80 @@
 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+							'create:creates a cask of the given name and opens it in an editor'
44+							'edit:edits the cask of the given name'
45+							'home:opens the homepage of the cask of the given name'
46+							'info:displays information about the cask of the given name'
47+							'install:installs the cask of the given name'
48+							'list:with no args, lists installed casks; given installed casks, lists installed files'
49+							'search:searches all known casks'
50+							'uninstall:uninstalls the cask of the given name'
51+						)
52+						_describe -t commands "brew cask subcommand" subcommands
53+					fi ;;
54+
55+				*)
56+					__call_original_brew ;;
57+			esac ;;
58+
59+		(options)
60+			local -a casks installed_casks
61+			local expl
62+			case "$line[2]" in
63+				list|uninstall)
64+					__brew_installed_casks
65+					_wanted installed_casks expl 'installed casks' compadd -a installed_casks ;;
66+				audit|edit|home|info|install)
67+					__brew_all_casks
68+					_wanted casks expl 'all casks' compadd -a casks ;;
69+			esac ;;
70+	esac
71+}
72+
73+__brew_all_casks() {
74+	casks=(`brew cask search`)
75+}
76+
77+__brew_installed_casks() {
78+	installed_casks=(`brew cask list`)
79+}
80+
81+__call_original_brew()
82+{
83+	local ret=1
84+	_call_function ret _brew
85+	compdef _brew-cask brew
86+}