brew-cask.plugin.zsh 2.38 KB
Newer Older
Patrick Stadler's avatar
Patrick Stadler committed
1
2
3
4
5
6
7
8
9
10
11
# Autocompletion for homebrew-cask.
#
# This script intercepts calls to the brew plugin and adds autocompletion
# for the cask subcommand.
#
# Author: https://github.com/pstadler

compdef _brew-cask brew

_brew-cask()
{
12
13
  local curcontext="$curcontext" state line
  typeset -A opt_args
Patrick Stadler's avatar
Patrick Stadler committed
14

15
16
17
18
  _arguments -C \
    ':command:->command' \
    ':subcmd:->subcmd' \
    '*::options:->options'
Patrick Stadler's avatar
Patrick Stadler committed
19

20
21
22
23
24
25
26
  case $state in
    (command)
      __call_original_brew
      cask_commands=(
        'cask:manage casks'
      )
      _describe -t commands 'brew cask command' cask_commands ;;
Patrick Stadler's avatar
Patrick Stadler committed
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    (subcmd)
      case "$line[1]" in
        cask)
          if (( CURRENT == 3 )); then
            local -a subcommands
            subcommands=(
              "alfred:used to modify Alfred's scope to include the Caskroom"
              'audit:verifies installability of casks'
              'checklinks:checks for bad cask links'
              'cleanup:cleans up cached downloads'
              'create:creates a cask of the given name and opens it in an editor'
              'doctor:checks for configuration issues'
              'edit:edits the cask of the given name'
              'fetch:downloads Cask resources to local cache'
              'home:opens the homepage of the cask of the given name'
              'info:displays information about the cask of the given name'
              'install:installs the cask of the given name'
              'list:with no args, lists installed casks; given installed casks, lists installed files'
              'search:searches all known casks'
              'uninstall:uninstalls the cask of the given name'
              "update:a synonym for 'brew update'"
            )
            _describe -t commands "brew cask subcommand" subcommands
          fi ;;
Patrick Stadler's avatar
Patrick Stadler committed
52

53
54
55
        *)
          __call_original_brew ;;
      esac ;;
Patrick Stadler's avatar
Patrick Stadler committed
56

57
58
59
60
61
62
63
64
65
66
67
68
    (options)
      local -a casks installed_casks
      local expl
      case "$line[2]" in
        list|uninstall)
          __brew_installed_casks
          _wanted installed_casks expl 'installed casks' compadd -a installed_casks ;;
        audit|edit|home|info|install)
          __brew_all_casks
          _wanted casks expl 'all casks' compadd -a casks ;;
      esac ;;
  esac
Patrick Stadler's avatar
Patrick Stadler committed
69
70
71
}

__brew_all_casks() {
72
  casks=(`brew cask search`)
Patrick Stadler's avatar
Patrick Stadler committed
73
74
75
}

__brew_installed_casks() {
76
  installed_casks=(`brew cask list`)
Patrick Stadler's avatar
Patrick Stadler committed
77
78
79
80
}

__call_original_brew()
{
81
82
83
  local ret=1
  _call_function ret _brew
  compdef _brew-cask brew
Patrick Stadler's avatar
Patrick Stadler committed
84
}