brew-cask.plugin.zsh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Autocompletion for homebrew-cask.
  2. #
  3. # This script intercepts calls to the brew plugin and adds autocompletion
  4. # for the cask subcommand.
  5. #
  6. # Author: https://github.com/pstadler
  7. compdef _brew-cask brew
  8. _brew-cask()
  9. {
  10. local curcontext="$curcontext" state line
  11. typeset -A opt_args
  12. _arguments -C \
  13. ':command:->command' \
  14. ':subcmd:->subcmd' \
  15. '*::options:->options'
  16. case $state in
  17. (command)
  18. __call_original_brew
  19. cask_commands=(
  20. 'cask:manage casks'
  21. )
  22. _describe -t commands 'brew cask command' cask_commands ;;
  23. (subcmd)
  24. case "$line[1]" in
  25. cask)
  26. if (( CURRENT == 3 )); then
  27. local -a subcommands
  28. subcommands=(
  29. "alfred:used to modify Alfred's scope to include the Caskroom"
  30. 'audit:verifies installability of casks'
  31. 'checklinks:checks for bad cask links'
  32. 'create:creates a cask of the given name and opens it in an editor'
  33. 'edit:edits the cask of the given name'
  34. 'home:opens the homepage of the cask of the given name'
  35. 'info:displays information about the cask of the given name'
  36. 'install:installs the cask of the given name'
  37. 'list:with no args, lists installed casks; given installed casks, lists installed files'
  38. 'search:searches all known casks'
  39. 'uninstall:uninstalls the cask of the given name'
  40. )
  41. _describe -t commands "brew cask subcommand" subcommands
  42. fi ;;
  43. *)
  44. __call_original_brew ;;
  45. esac ;;
  46. (options)
  47. local -a casks installed_casks
  48. local expl
  49. case "$line[2]" in
  50. list|uninstall)
  51. __brew_installed_casks
  52. _wanted installed_casks expl 'installed casks' compadd -a installed_casks ;;
  53. audit|edit|home|info|install)
  54. __brew_all_casks
  55. _wanted casks expl 'all casks' compadd -a casks ;;
  56. esac ;;
  57. esac
  58. }
  59. __brew_all_casks() {
  60. casks=(`brew cask search`)
  61. }
  62. __brew_installed_casks() {
  63. installed_casks=(`brew cask list`)
  64. }
  65. __call_original_brew()
  66. {
  67. local ret=1
  68. _call_function ret _brew
  69. compdef _brew-cask brew
  70. }