f2580833c071d19a0b738fdbadd0bdb735ddb86c

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Merge branch 'apjanke-cask-homebrew-paths'

Diff

 1diff --git a/plugins/cask/README.md b/plugins/cask/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..6457fd858186d72670f4c791ed9f42b90b615969
 4--- /dev/null
 5+++ b/plugins/cask/README.md
 6@@ -0,0 +1,11 @@
 7+# cask plugin
 8+
 9+Loads `cask` completion from non-standard locations, such as if installed
10+via Homebrew or others. To enable it, add `cask` to your plugins array:
11+
12+```zsh
13+plugins=(... cask)
14+```
15+
16+Make sure you have the `cask` directory in your `$PATH` before loading
17+Oh My Zsh, otherwise you'll get the "command not found" error.
18diff --git a/plugins/cask/cask.plugin.zsh b/plugins/cask/cask.plugin.zsh
19index c558629243d2274d8c380bc807f08d5f53690824..29120b3062ddfaa8f5775449da7019cd18639c6a 100644
20--- a/plugins/cask/cask.plugin.zsh
21+++ b/plugins/cask/cask.plugin.zsh
22@@ -1,5 +1,26 @@
23-if which cask &> /dev/null; then
24-  source $(dirname $(which cask))/../etc/cask_completion.zsh
25-else
26-  print "zsh cask plugin: cask not found"
27-fi
28+() {
29+  emulate -L zsh
30+
31+  if ! (( $+commands[cask] )); then
32+    print "zsh cask plugin: cask command not found" >&2
33+    return
34+  fi
35+
36+  cask_base=${commands[cask]:h:h}
37+
38+  # Plain cask installation location (for Cask 0.7.2 and earlier)
39+  comp_files=($cask_base/etc/cask_completion.zsh)
40+
41+  # Mac Homebrew installs the completion in a different location
42+  if (( $+commands[brew] )); then
43+    comp_files+=($(brew --prefix)/share/zsh/site-functions/cask_completion.zsh)
44+  fi
45+
46+  # Load first found file
47+  for f in $comp_files; do
48+    if [[ -f "$f" ]]; then
49+      source "$f"
50+      break
51+    fi
52+  done
53+}