a7e60e4a9367117fa39ecf1de9ce63383878538b

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

Message

Style fixes and shorter command lookup

Diff

 1diff --git a/plugins/cask/cask.plugin.zsh b/plugins/cask/cask.plugin.zsh
 2index bc0006d9f20ca622595a5d1b6b34b7ffba0b9b39..29120b3062ddfaa8f5775449da7019cd18639c6a 100644
 3--- a/plugins/cask/cask.plugin.zsh
 4+++ b/plugins/cask/cask.plugin.zsh
 5@@ -1,21 +1,26 @@
 6 () {
 7-  if which cask &> /dev/null; then
 8-    local cask_bin cask_base f comp_files
 9-    cask_bin=$(which cask)
10-    cask_base=${cask_bin:h:h}
11-    # Plain cask installation location (for Cask 0.7.2 and earlier)
12-    comp_files=( $cask_base/etc/cask_completion.zsh )
13-    # Mac Homebrew installs the completion in a different location
14-    if which brew &> /dev/null; then
15-      comp_files+=`brew --prefix`/share/zsh/site-functions/cask_completion.zsh
16-    fi
17-    for f in $comp_files; do
18-      if [[ -f $f ]]; then
19-        source $f;
20-        break;
21-      fi
22-    done
23-  else
24-    print "zsh cask plugin: cask not found"
25+  emulate -L zsh
26+
27+  if ! (( $+commands[cask] )); then
28+    print "zsh cask plugin: cask command not found" >&2
29+    return
30+  fi
31+
32+  cask_base=${commands[cask]:h:h}
33+
34+  # Plain cask installation location (for Cask 0.7.2 and earlier)
35+  comp_files=($cask_base/etc/cask_completion.zsh)
36+
37+  # Mac Homebrew installs the completion in a different location
38+  if (( $+commands[brew] )); then
39+    comp_files+=($(brew --prefix)/share/zsh/site-functions/cask_completion.zsh)
40   fi
41-}
42+
43+  # Load first found file
44+  for f in $comp_files; do
45+    if [[ -f "$f" ]]; then
46+      source "$f"
47+      break
48+    fi
49+  done
50+}