├── LICENSE ├── README.md ├── brew-cask.fish └── homebrew-cask-completion.bash /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause 2 | Copyright (c) 2009-2016, Homebrew contributors 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Homebrew Cask Completion 2 | 3 | Bash and fish auto-completion scripts for [brew-cask](https://github.com/caskroom/homebrew-cask/). Does not work for `brew cask` currently. 4 | 5 | If you looking for zsh support, please use [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh). 6 | 7 | ## Installation 8 | 9 | Just type: 10 | 11 | brew install homebrew/completions/brew-cask-completion 12 | 13 | Or: 14 | 15 | brew tap homebrew/completions 16 | brew install brew-cask-completion 17 | 18 | ## Manual Installation 19 | 20 | Bash: 21 | 22 | git clone https://github.com/xyb/homebrew-cask-completion.git 23 | cd homebrew-cask-completion/ 24 | ln -s $(pwd)/homebrew-cask-completion.bash $(brew --prefix)/etc/bash_completion.d/brew-cask 25 | 26 | Fish: 27 | 28 | git clone https://github.com/xyb/homebrew-cask-completion.git 29 | cd homebrew-cask-completion/ 30 | mkdir -p ~/.config/fish/completions 31 | ln -s $(pwd)/brew-cask.fish ~/.config/fish/completions 32 | -------------------------------------------------------------------------------- /brew-cask.fish: -------------------------------------------------------------------------------- 1 | # Fish completion script for brew-cask(1) 2 | 3 | function __fish_brew_cask_needs_command 4 | set cmd (commandline -opc) 5 | if [ (count $cmd) -eq 1 -a $cmd[1] = 'brew-cask' ] 6 | return 0 7 | end 8 | return 1 9 | end 10 | 11 | function __fish_brew_cask_using_command 12 | set cmd (commandline -opc) 13 | if [ (count $cmd) -gt 1 ] 14 | if [ $argv[1] = $cmd[2] ] 15 | return 0 16 | end 17 | end 18 | return 1 19 | end 20 | 21 | function __fish_brew_cask_casks 22 | find (brew --repository)/Library/Taps/caskroom/homebrew-cask/Casks -name "*.rb" -print | sed 's/.rb$//' | sed "s|^.*/||" 23 | end 24 | 25 | function __fish_brew_cask_caskroom 26 | ls /opt/homebrew-cask/Caskroom/ 27 | end 28 | 29 | function __fish_brew_cask_installed_casks 30 | brew-cask list -1 31 | end 32 | 33 | 34 | ############ 35 | # commands # 36 | ############ 37 | 38 | # alfred 39 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a alfred -d 'Displays note about new built-in alfred support' 40 | 41 | # audit 42 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a audit -d 'Check casks' 43 | complete -f -c brew-cask -n '__fish_brew_cask_using_command audit' -a '(__fish_brew_cask_casks)' 44 | 45 | # cat 46 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a cat -d 'Display cask' 47 | complete -f -c brew-cask -n '__fish_brew_cask_using_command cat' -a '(__fish_brew_cask_casks)' 48 | 49 | # cleanup 50 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a cleanup -d 'Clean up cached downloads and tracker symlinks' 51 | complete -f -c brew-cask -n '__fish_brew_cask_using_command cleanup' -l outdated -d 'Only clean up cached downloads older than 10 days old' 52 | complete -f -c brew-cask -n '__fish_brew_cask_using_command cleanup' -a '(__fish_brew_cask_installed_casks)' 53 | 54 | # create 55 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a create -d 'Generate a Cask definition file' 56 | 57 | # doctor 58 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a 'doctor dr' -d 'Check for configuration issues' 59 | 60 | # edit 61 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a 'edit' -d 'Open cask definition file for editing' 62 | complete -f -c brew-cask -n '__fish_brew_cask_using_command edit' -a '(__fish_brew_cask_casks)' 63 | 64 | # fetch 65 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a fetch -d 'Download resources for cask' 66 | complete -f -c brew-cask -n '__fish_brew_cask_using_command fetch' -l force -d 'Force re-download even if the resources are already cached' 67 | complete -f -c brew-cask -n '__fish_brew_cask_using_command fetch' -a '(__fish_brew_cask_casks)' 68 | 69 | # help 70 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a 'help' -d 'Display help' 71 | 72 | # home 73 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a 'home homepage' -d 'Open cask\'s homepage' 74 | complete -c brew-cask -n '__fish_brew_cask_using_command home' -a '(__fish_brew_cask_casks)' 75 | 76 | # info 77 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a 'info abv' -d 'Display information about cask' 78 | complete -c brew-cask -n '__fish_brew_cask_using_command info' -a '(__fish_brew_cask_casks)' 79 | 80 | # install 81 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a 'install' -d 'Install cask' 82 | complete -f -c brew-cask -n '__fish_brew_cask_using_command install' -l force -d 'Force install' 83 | complete -c brew-cask -n '__fish_brew_cask_using_command install' -a '(__fish_brew_cask_casks)' 84 | 85 | # list 86 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a 'list ls' -d 'List all installed casks' 87 | complete -f -c brew-cask -n '__fish_brew_cask_using_command list' -s 1 -d 'Always format the output in a single column' 88 | complete -f -c brew-cask -n '__fish_brew_cask_using_command ls' -s 1 -d 'Always format the output in a single column' 89 | complete -f -c brew-cask -n '__fish_brew_cask_using_command list' -s l -d 'Give a more detailed listing' 90 | complete -f -c brew-cask -n '__fish_brew_cask_using_command ls' -s l -d 'Give a more detailed listing' 91 | complete -c brew-cask -n '__fish_brew_cask_using_command list' -a '(__fish_brew_cask_casks)' 92 | complete -c brew-cask -n '__fish_brew_cask_using_command ls' -a '(__fish_brew_cask_casks)' 93 | 94 | # search 95 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a 'search -S' -d 'Display all casks or search by name' 96 | 97 | # uninstall 98 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a 'uninstall remove rm' -d 'Uninstall cask' 99 | complete -f -c brew-cask -n '__fish_brew_cask_using_command uninstall' -a '(__fish_brew_cask_installed_casks)' 100 | complete -f -c brew-cask -n '__fish_brew_cask_using_command remove' -a '(__fish_brew_cask_installed_casks)' 101 | complete -f -c brew-cask -n '__fish_brew_cask_using_command rm' -a '(__fish_brew_cask_installed_casks)' 102 | complete -f -c brew-cask -n '__fish_brew_cask_using_command uninstall' -l force -d 'Uninstall even cask not present' 103 | complete -f -c brew-cask -n '__fish_brew_cask_using_command remove' -l force -d 'Uninstall even cask not present' 104 | complete -f -c brew-cask -n '__fish_brew_cask_using_command rm' -l force -d 'Uninstall even cask not present' 105 | 106 | # zap 107 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -a zap -d 'Unconditionally remove all files associated with casks' 108 | complete -c brew-cask -n '__fish_brew_cask_using_command zap' -a '(__fish_brew_cask_caskroom)' 109 | 110 | 111 | ############ 112 | # switches # 113 | ############ 114 | 115 | # --force 116 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l force -d 'Force install cask even exists' 117 | 118 | # --caskroom 119 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l caskroom -d 'Location of the Caskroom, where all binaries are stored' 120 | 121 | # --verbose 122 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l verbose -d 'Give additional feedback during installation' 123 | 124 | # --appdir 125 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l appdir -d 'Target location for Application links' 126 | 127 | # --colorpickerdir 128 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l appdir -d 'Target location for Color Picker links' 129 | 130 | # --prefpanedir 131 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l prefpanedir -d 'Target location for Preference Pane links' 132 | 133 | # --qlplugindir 134 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l qlplugindir -d 'Target location for QuickLook Plugin links' 135 | 136 | # --fontdir 137 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l fontdir -d 'Target location for Font links' 138 | 139 | # --servicedir 140 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l servicedir -d 'Target location for Service links' 141 | 142 | # --input_methoddir 143 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l input_methoddir -d 'Target location for Input Method links' 144 | 145 | # --internet_plugindir 146 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l internet_plugindir -d 'Target location for Internet Plugin links' 147 | 148 | # --screen_saverdir 149 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l screen_saverdir -d 'Target location for Screen Saver links' 150 | 151 | # --no-binaries 152 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l no-binaries -d 'Do not link ahelpera executables to /usr/local/bin' 153 | 154 | # --binarydir 155 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l binarydir -d 'Target location for ahelpera executable links' 156 | 157 | # --debug 158 | complete -f -c brew-cask -n '__fish_brew_cask_needs_command' -l debug -d 'Output debugging information' 159 | -------------------------------------------------------------------------------- /homebrew-cask-completion.bash: -------------------------------------------------------------------------------- 1 | # Bash completion script for brew-cask(1) 2 | 3 | __brew_caskcomp_words_include () 4 | { 5 | local i=1 6 | while [[ $i -lt $COMP_CWORD ]]; do 7 | if [[ "${COMP_WORDS[i]}" = "$1" ]]; then 8 | return 0 9 | fi 10 | i=$((++i)) 11 | done 12 | return 1 13 | } 14 | 15 | # Find the previous non-switch word 16 | __brew_caskcomp_prev () 17 | { 18 | local idx=$((COMP_CWORD - 1)) 19 | local prv="${COMP_WORDS[idx]}" 20 | while [[ $prv == -* ]]; do 21 | idx=$((--idx)) 22 | prv="${COMP_WORDS[idx]}" 23 | done 24 | echo "$prv" 25 | } 26 | 27 | __brew_caskcomp () 28 | { 29 | # break $1 on space, tab, and newline characters, 30 | # and turn it into a newline separated list of words 31 | local list s sep=$'\n' IFS=$' '$'\t'$'\n' 32 | local cur="${COMP_WORDS[COMP_CWORD]}" 33 | 34 | for s in $1; do 35 | __brew_caskcomp_words_include "$s" && continue 36 | list="$list$s$sep" 37 | done 38 | 39 | IFS=$sep 40 | COMPREPLY=($(compgen -W "$list" -- "$cur")) 41 | } 42 | 43 | # Don't use __brew_caskcomp() in any of the __brew_cask_complete_foo functions, as 44 | # it is too slow and is not worth it just for duplicate elimination. 45 | __brew_cask_complete_formulae () 46 | { 47 | local cur="${COMP_WORDS[COMP_CWORD]}" 48 | local lib=$(brew --repository)/Library 49 | local taps=${lib}/Taps 50 | local casks=${lib}/Taps/caskroom/homebrew-cask/Casks 51 | local ff=$(\ls ${casks} 2>/dev/null | sed 's/\.rb//g') 52 | 53 | COMPREPLY=($(compgen -W "$ff" -- "$cur")) 54 | } 55 | 56 | __brew_cask_complete_installed () 57 | { 58 | local cur="${COMP_WORDS[COMP_CWORD]}" 59 | local inst=$(brew-cask list -1) 60 | COMPREPLY=($(compgen -W "$inst" -- "$cur")) 61 | } 62 | 63 | __brew_cask_complete_caskroom () 64 | { 65 | local cur="${COMP_WORDS[COMP_CWORD]}" 66 | local caskroom_dir=/opt/homebrew-cask/Caskroom/ 67 | local files=$(\ls ${caskroom_dir} 2>/dev/null) 68 | COMPREPLY=($(compgen -W "$files" -- "$cur")) 69 | } 70 | 71 | _brew_cask_cleanup () 72 | { 73 | local cur="${COMP_WORDS[COMP_CWORD]}" 74 | case "$cur" in 75 | -*) 76 | __brew_caskcomp "--force" 77 | return 78 | ;; 79 | esac 80 | __brew_cask_complete_installed 81 | } 82 | 83 | _brew_cask_fetch () 84 | { 85 | local cur="${COMP_WORDS[COMP_CWORD]}" 86 | local prv=$(__brew_caskcomp_prev) 87 | case "$cur" in 88 | -*) 89 | __brew_caskcomp "--force" 90 | return 91 | ;; 92 | esac 93 | __brew_cask_complete_formulae 94 | } 95 | 96 | _brew_cask_list () 97 | { 98 | local cur="${COMP_WORDS[COMP_CWORD]}" 99 | 100 | case "$cur" in 101 | -*) 102 | __brew_caskcomp "-1 -l --versions" 103 | return 104 | ;; 105 | esac 106 | 107 | __brew_cask_complete_installed 108 | } 109 | 110 | _brew_cask_uninstall () 111 | { 112 | local cur="${COMP_WORDS[COMP_CWORD]}" 113 | case "$cur" in 114 | -*) 115 | __brew_caskcomp "--force" 116 | return 117 | ;; 118 | esac 119 | __brew_cask_complete_installed 120 | } 121 | 122 | _brew_cask () 123 | { 124 | local i=1 cmd 125 | 126 | # find the subcommand 127 | while [[ $i -lt $COMP_CWORD ]]; do 128 | local s="${COMP_WORDS[i]}" 129 | case "$s" in 130 | --*) 131 | cmd="$s" 132 | break 133 | ;; 134 | -*) 135 | ;; 136 | *) 137 | cmd="$s" 138 | break 139 | ;; 140 | esac 141 | i=$((++i)) 142 | done 143 | 144 | if [[ $i -eq $COMP_CWORD ]]; then 145 | __brew_caskcomp "abv alfred audit cat cleanup create doctor edit fetch home info install list ls remove rm search uninstall zap -S --force --caskroom --verbose --appdir --colorpickerdir --prefpanedir --qlplugindir --fontdir --servicedir --input_methoddir --internet_plugindir --screen_saverdir --no-binaries --binarydir --debug" 146 | return 147 | fi 148 | 149 | # subcommands have their own completion functions 150 | case "$cmd" in 151 | audit) __brew_cask_complete_formulae ;; 152 | cat|edit|home) __brew_cask_complete_formulae ;; 153 | cleanup) _brew_cask_cleanup ;; 154 | fetch) _brew_cask_fetch ;; 155 | info|abv) __brew_cask_complete_formulae ;; 156 | install|instal) __brew_cask_complete_formulae ;; 157 | list|ls) _brew_cask_list ;; 158 | uninstall|remove|rm) _brew_cask_uninstall ;; 159 | zap) __brew_cask_complete_caskroom ;; 160 | *) ;; 161 | esac 162 | } 163 | 164 | # keep around for compatibility 165 | _brew_cask_to_completion () 166 | { 167 | _brew_cask 168 | } 169 | 170 | complete -o bashdefault -o default -F _brew_cask brew-cask 171 | --------------------------------------------------------------------------------