brew-cask.plugin.zsh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. 'cleanup:cleans up cached downloads'
  33. 'create:creates a cask of the given name and opens it in an editor'
  34. 'doctor:checks for configuration issues'
  35. 'edit:edits the cask of the given name'
  36. 'fetch:downloads Cask resources to local cache'
  37. 'home:opens the homepage of the cask of the given name'
  38. 'info:displays information about the cask of the given name'
  39. 'install:installs the cask of the given name'
  40. 'list:with no args, lists installed casks; given installed casks, lists installed files'
  41. 'search:searches all known casks'
  42. 'uninstall:uninstalls the cask of the given name'
  43. "update:a synonym for 'brew update'"
  44. )
  45. _describe -t commands "brew cask subcommand" subcommands
  46. fi ;;
  47. *)
  48. __call_original_brew ;;
  49. esac ;;
  50. (options)
  51. local -a casks installed_casks
  52. local expl
  53. case "$line[2]" in
  54. list|uninstall)
  55. __brew_installed_casks
  56. _wanted installed_casks expl 'installed casks' compadd -a installed_casks ;;
  57. audit|edit|home|info|install)
  58. __brew_all_casks
  59. _wanted casks expl 'all casks' compadd -a casks ;;
  60. esac ;;
  61. esac
  62. }
  63. __brew_all_casks() {
  64. casks=(`brew cask search`)
  65. }
  66. __brew_installed_casks() {
  67. installed_casks=(`brew cask list`)
  68. }
  69. __call_original_brew()
  70. {
  71. local ret=1
  72. _call_function ret _brew
  73. compdef _brew-cask brew
  74. }