From 4ff6ea950bf97251e71e0ffda089c2edcfd780dc Mon Sep 17 00:00:00 2001 From: Joshua McKinney Date: Fri, 19 Aug 2016 11:44:06 -0500 Subject: [PATCH 1/7] Add Homebrew Cask completions This completion was originally sourced from the oh-my-zsh brew cask plugin. (https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/brew-cask/brew-cask.plugin.zsh) The rationale for splitting this from the original omz plugin is to address the following issues: 1. it is part of oh-my-zsh which some have chosen not to use (e.g. zprezto users) 2. it acts as a script overriding the existing brew completion rather than as a standard autoloadable file, this means it must be manually installed rather than automatically installed as part of compinit, and may cause issues with future commands added to homebrew. The changes from the plugin are to fix item 2, as well as update the commands to those current in homebrew cask. --- share/zsh/site-functions/_brew_cask | 83 +++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 share/zsh/site-functions/_brew_cask diff --git a/share/zsh/site-functions/_brew_cask b/share/zsh/site-functions/_brew_cask new file mode 100644 index 0000000000..59fe179501 --- /dev/null +++ b/share/zsh/site-functions/_brew_cask @@ -0,0 +1,83 @@ +#compdef brew-cask +#autoload + +# Autocompletion for homebrew-cask (https://github.com/caskroom/homebrew-cask/). +# +# Originally sourced from the oh-my-zsh +# https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/brew-cask/brew-cask.plugin.zsh +# +# The MIT License (MIT) +# +# Copyright (c) 2009-2016 Robby Russell and contributors +# See the full list at https://github.com/robbyrussell/oh-my-zsh/contributors +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +__brew_all_casks() { + brew cask search +} + +__brew_installed_casks() { + brew cask list|sed 's/(!)//' +} + +_brew_cask() +{ + local curcontext="$curcontext" state state_descr line + typeset -A opt_args + + _arguments -C \ + ':subcmd:->subcmd' \ + '*::options:->options' + + case $state in + (subcmd) + local -a subcommands + subcommands=( + 'audit:verifies installability of Casks' + 'cat:dump raw source of the given Cask to the standard output' + 'cleanup:cleans up cached downloads and tracker symlinks' + 'create:creates the given Cask and opens it in an editor' + 'doctor:checks for configuration issues' + 'edit:edits the given Cask' + 'fetch:downloads remote application files to local cache' + 'home:opens the homepage of the given Cask' + 'info:displays information about the given Cask' + 'install:installs the given Cask' + 'list:with no args, lists installed Casks; given installed Casks, lists staged files' + 'search:searches all known Casks' + 'style:checks Cask style using RuboCop' + 'uninstall:uninstalls the given Cask' + "update:a synonym for 'brew update'" + 'zap:zaps all files associated with the given Cask' + ) + _describe -t commands "brew cask subcommand" subcommands ;; + (options) + local -a casks installed_casks + local expl + case "$line[1]" in + list|uninstall) + installed_casks=($(__brew_installed_casks)) + _wanted installed_casks expl 'installed casks' compadd -a installed_casks ;; + audit|cat|edit|fetch|home|info|install|zap) + casks=($(__brew_all_casks)) + _wanted casks expl 'all casks' compadd -a casks ;; + esac ;; + esac +} From abae36d96dd8cd7c6abf6650204ccf4791948dd9 Mon Sep 17 00:00:00 2001 From: Joshua McKinney Date: Fri, 19 Aug 2016 12:06:59 -0500 Subject: [PATCH 2/7] Refactor brew-cask zsh completion to functions --- share/zsh/site-functions/_brew_cask | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/share/zsh/site-functions/_brew_cask b/share/zsh/site-functions/_brew_cask index 59fe179501..d31d717920 100644 --- a/share/zsh/site-functions/_brew_cask +++ b/share/zsh/site-functions/_brew_cask @@ -30,11 +30,17 @@ # SOFTWARE. __brew_all_casks() { - brew cask search + local -a list + local expl + list=( $(brew cask search) ) + _wanted list expl 'all casks' compadd -a list } __brew_installed_casks() { - brew cask list|sed 's/(!)//' + local -a list + local expl + list=( $(brew cask list|sed 's/(!)//') ) + _wanted list expl 'installed casks' compadd -a list } _brew_cask() @@ -69,15 +75,11 @@ _brew_cask() ) _describe -t commands "brew cask subcommand" subcommands ;; (options) - local -a casks installed_casks - local expl case "$line[1]" in list|uninstall) - installed_casks=($(__brew_installed_casks)) - _wanted installed_casks expl 'installed casks' compadd -a installed_casks ;; + __brew_installed_casks ;; audit|cat|edit|fetch|home|info|install|zap) - casks=($(__brew_all_casks)) - _wanted casks expl 'all casks' compadd -a casks ;; + __brew_all_casks ;; esac ;; esac } From 34bf31370465fa64ecbde7bb3a57abddfb4d8ec9 Mon Sep 17 00:00:00 2001 From: Joshua McKinney Date: Fri, 19 Aug 2016 15:36:30 -0500 Subject: [PATCH 3/7] Add missing brew-cask commands to zsh completion --- share/zsh/site-functions/_brew_cask | 190 +++++++++++++++++++++++----- 1 file changed, 160 insertions(+), 30 deletions(-) diff --git a/share/zsh/site-functions/_brew_cask b/share/zsh/site-functions/_brew_cask index d31d717920..01d44c0c6e 100644 --- a/share/zsh/site-functions/_brew_cask +++ b/share/zsh/site-functions/_brew_cask @@ -10,6 +10,7 @@ # # Copyright (c) 2009-2016 Robby Russell and contributors # See the full list at https://github.com/robbyrussell/oh-my-zsh/contributors +# Copyright (c) 2016 Joshua McKinney # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -29,6 +30,10 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +# only display the main commands (but enable completing aliases like 'ls') +zstyle -T ':completion:*:*:*:brew-cask:*' tag-order && \ + zstyle ':completion:*:*:*:brew-cask:*' tag-order 'commands' + __brew_all_casks() { local -a list local expl @@ -43,43 +48,168 @@ __brew_installed_casks() { _wanted list expl 'installed casks' compadd -a list } +__brew_cask_commands() { + local -a commands + commands=( + 'audit:verifies installability of Casks' + 'cat:dump raw source of the given Cask to the standard output' + 'cleanup:cleans up cached downloads and tracker symlinks' + 'create:creates the given Cask and opens it in an editor' + 'doctor:checks for configuration issues' + 'edit:edits the given Cask' + 'fetch:downloads remote application files to local cache' + 'home:opens the homepage of the given Cask' + 'info:displays information about the given Cask' + 'install:installs the given Cask' + 'list:with no args, lists installed Casks; given installed Casks, lists staged files' + 'search:searches all known Casks' + 'style:checks Cask style using RuboCop' + 'uninstall:uninstalls the given Cask' + "update:a synonym for 'brew update'" + 'zap:zaps all files associated with the given Cask' + ) + _describe -t commands "brew cask command" commands +} + +__brew_cask_aliases() { + local -a aliases + aliases=( + 'dr' + 'homepage' + 'abv' + 'ls' + '-S' + 'rm' + 'remove' + ) + _describe -t commands "brew cask command aliases" aliases +} + +__brew_cask_command() { + local command="$1" + local completion_func="_brew_cask_${command//-/_}" + declare -f "$completion_func" >/dev/null && "$completion_func" && return +} + +_brew_cask_abv() { + _brew_cask_info +} + +_brew_cask_audit() { + __brew_all_casks +} + +_brew_cask_cat() { + __brew_all_casks +} + +_brew_cask_cat() { + __brew_all_casks +} + +_brew_cask_cleanup() { + _arguments '--outdated' +} + +_brew_cask_create() { + _arguments '*::token:' +} + +_brew_cask_edit() { + __brew_all_casks +} + +_brew_cask_fetch() { + _arguments : \ + '--force' \ + '*::token:__brew_all_casks' +} + +_brew_cask_home() { + __brew_all_casks +} + +_brew_cask_homepage() { + __brew_cask_home +} + +_brew_cask_info() { + __brew_all_casks +} + +_brew_cask_install() { + _arguments : \ + '--force' \ + '--skip-cask-deps' \ + '--require-sha' \ + '*::token:__brew_all_casks' +} + +_brew_cask_list() { + _arguments : \ + '-1[format output in a single column]' \ + '-l[format as detailed list]' \ + '*::token:__brew_installed_casks' +} + +_brew_cask_ls() { + _brew_cask_list +} + +_brew_cask_remove() { + _brew_cask_uninstall +} + +_brew_cask_rm() { + _brew_cask_uninstall +} + +_brew_cask_style() { + _arguments : \ + '--fix' \ + '*::token:__brew_all_casks' +} + +_brew_cask_uninstall() { + _arguments : \ + '--force' \ + '*::token:__brew_installed_casks' +} + +_brew_cask_zap() { + __brew_all_casks +} + _brew_cask() { local curcontext="$curcontext" state state_descr line typeset -A opt_args - _arguments -C \ - ':subcmd:->subcmd' \ + _arguments -C : \ + '--verbose:Give additional feedback during installation.' \ + '--appdir=-:Target location for Applications. The default value is /Applications:' \ + '--colorpickerdir=-:Target location for Color Pickers. The default value is ~/Library/ColorPickers.' \ + '--prefpanedir=-:Target location for Preference Panes. The default value is ~/Library/PreferencePanes.' \ + '--qlplugindir=-:Target location for QuickLook Plugins. The default value is ~/Library/QuickLook.' \ + '--fontdir=-:Target location for Fonts. The default value is ~/Library/Fonts.' \ + '--servicedir=-:Target location for Services. The default value is ~/Library/Services.' \ + '--input_methoddir=-:Target location for Input Methods. The default value is ~/Library/Input Methods.' \ + '--internet_plugindir=-:Target location for Internet Plugins. The default value is ~/Library/Internet Plug-Ins.' \ + '--audio_unit_plugindir=-:Target location for Audio Unit Plugins. The default value is ~/Library/Audio/Plug-Ins/Components.' \ + '--vst_plugindir=-:Target location for VST Plugins. The default value is ~/Library/Audio/Plug-Ins/VST.' \ + '--vst3_plugindir=-:Target location for VST3 Plugins. The default value is ~/Library/Audio/Plug-Ins/VST3.' \ + '--screen_saverdir=-:Target location for Screen Savers. The default value is ~/Library/Screen Savers.' \ + '--no-binaries:Do not link "helper" executables to /usr/local/bin.' \ + '--debug:Output debugging information of use to Cask authors and developers.' \ + ':command:->command' \ '*::options:->options' - case $state in - (subcmd) - local -a subcommands - subcommands=( - 'audit:verifies installability of Casks' - 'cat:dump raw source of the given Cask to the standard output' - 'cleanup:cleans up cached downloads and tracker symlinks' - 'create:creates the given Cask and opens it in an editor' - 'doctor:checks for configuration issues' - 'edit:edits the given Cask' - 'fetch:downloads remote application files to local cache' - 'home:opens the homepage of the given Cask' - 'info:displays information about the given Cask' - 'install:installs the given Cask' - 'list:with no args, lists installed Casks; given installed Casks, lists staged files' - 'search:searches all known Casks' - 'style:checks Cask style using RuboCop' - 'uninstall:uninstalls the given Cask' - "update:a synonym for 'brew update'" - 'zap:zaps all files associated with the given Cask' - ) - _describe -t commands "brew cask subcommand" subcommands ;; + case "$state" in + (command) + _alternative -C 'brew-cask' \ + 'aliases:alias:__brew_cask_aliases' \ + 'commands:command:__brew_cask_commands' ;; (options) - case "$line[1]" in - list|uninstall) - __brew_installed_casks ;; - audit|cat|edit|fetch|home|info|install|zap) - __brew_all_casks ;; - esac ;; + __brew_cask_command "$line[1]" ;; esac } From db18a13389ff3e09fc5a9ed98328b99b19da0c16 Mon Sep 17 00:00:00 2001 From: Joshua McKinney Date: Fri, 19 Aug 2016 15:50:43 -0500 Subject: [PATCH 4/7] Add brew-cask arg descriptions to zsh completion --- share/zsh/site-functions/_brew_cask | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/share/zsh/site-functions/_brew_cask b/share/zsh/site-functions/_brew_cask index 01d44c0c6e..bed090cb09 100644 --- a/share/zsh/site-functions/_brew_cask +++ b/share/zsh/site-functions/_brew_cask @@ -108,7 +108,7 @@ _brew_cask_cat() { } _brew_cask_cleanup() { - _arguments '--outdated' + _arguments '--outdated:only clean up cached downloads older than 10 days old' } _brew_cask_create() { @@ -121,7 +121,7 @@ _brew_cask_edit() { _brew_cask_fetch() { _arguments : \ - '--force' \ + '--force:force re-download even if the files are already cached' \ '*::token:__brew_all_casks' } @@ -139,9 +139,9 @@ _brew_cask_info() { _brew_cask_install() { _arguments : \ - '--force' \ - '--skip-cask-deps' \ - '--require-sha' \ + '--force:re-install even if the Cask appears to be already present' \ + '--skip-cask-deps:skip any Cask dependencies' \ + '--require-sha:abort installation if the Cask does not have a checksum defined' \ '*::token:__brew_all_casks' } @@ -166,13 +166,13 @@ _brew_cask_rm() { _brew_cask_style() { _arguments : \ - '--fix' \ + '--fix:auto-correct any style errors if possible' \ '*::token:__brew_all_casks' } _brew_cask_uninstall() { _arguments : \ - '--force' \ + '--force:uninstall even if the Cask does not appear to be present' \ '*::token:__brew_installed_casks' } From 3f75cb06c61ac82873ebcbfd91d7e6bb17675d1d Mon Sep 17 00:00:00 2001 From: Joshua McKinney Date: Fri, 19 Aug 2016 15:52:22 -0500 Subject: [PATCH 5/7] Update brew-cask zsh completions header --- share/zsh/site-functions/_brew_cask | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/share/zsh/site-functions/_brew_cask b/share/zsh/site-functions/_brew_cask index bed090cb09..2fd65c4d6e 100644 --- a/share/zsh/site-functions/_brew_cask +++ b/share/zsh/site-functions/_brew_cask @@ -1,11 +1,9 @@ #compdef brew-cask #autoload -# Autocompletion for homebrew-cask (https://github.com/caskroom/homebrew-cask/). -# -# Originally sourced from the oh-my-zsh -# https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/brew-cask/brew-cask.plugin.zsh -# +# Zsh Autocompletion script for Homebrew Cask +# https://github.com/homebrew/brew + # The MIT License (MIT) # # Copyright (c) 2009-2016 Robby Russell and contributors From 1e152f1417ce6df3d4959fc44ce15d48a75cc89f Mon Sep 17 00:00:00 2001 From: Joshua McKinney Date: Wed, 14 Sep 2016 10:12:46 -0500 Subject: [PATCH 6/7] Fix first _brew_cask completion function call Without a call to _brew_cask at the end of the script, the first completion does not work as zsh just autoloads the function without executing it. --- share/zsh/site-functions/_brew_cask | 2 ++ 1 file changed, 2 insertions(+) diff --git a/share/zsh/site-functions/_brew_cask b/share/zsh/site-functions/_brew_cask index 2fd65c4d6e..7120dcbf5d 100644 --- a/share/zsh/site-functions/_brew_cask +++ b/share/zsh/site-functions/_brew_cask @@ -211,3 +211,5 @@ _brew_cask() __brew_cask_command "$line[1]" ;; esac } + +_brew_cask "$@" From 1af02dbb8a080364848cc22b474ca0b03caaca06 Mon Sep 17 00:00:00 2001 From: Joshua McKinney Date: Wed, 14 Sep 2016 10:27:44 -0500 Subject: [PATCH 7/7] _brew_cask completion re-license to BSD The original script was MIT licensed, removing this license and relicensing it under Homebrew's default license (BSD 2 Clause). Patrick Stadler (https://github.com/pstadler) gave his ok on this at: https://github.com/joshka/brew-cask-zsh-completions/issues/1 --- share/zsh/site-functions/_brew_cask | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/share/zsh/site-functions/_brew_cask b/share/zsh/site-functions/_brew_cask index 7120dcbf5d..fb969ffe4a 100644 --- a/share/zsh/site-functions/_brew_cask +++ b/share/zsh/site-functions/_brew_cask @@ -2,31 +2,11 @@ #autoload # Zsh Autocompletion script for Homebrew Cask -# https://github.com/homebrew/brew +# https://github.com/homebrew/brew -# The MIT License (MIT) -# -# Copyright (c) 2009-2016 Robby Russell and contributors -# See the full list at https://github.com/robbyrussell/oh-my-zsh/contributors -# Copyright (c) 2016 Joshua McKinney -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. +# Authors: +# Patrick Stadler (https://github.com/pstadler) +# Josh McKinney (https://github.com/joshka) # only display the main commands (but enable completing aliases like 'ls') zstyle -T ':completion:*:*:*:brew-cask:*' tag-order && \