_brew 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #compdef brew
  2. #autoload
  3. # imported from https://github.com/Homebrew/homebrew/blob/29f73d2212c2b202fe25f69dcbf440d8391fa4c9/Library/Contributions/brew_zsh_completion.zsh
  4. # Brew ZSH completion function
  5. # Drop this somewhere in your $fpath (like /usr/share/zsh/site-functions)
  6. # and rename it _brew
  7. #
  8. # altered from _fink
  9. _brew_all_formulae() {
  10. formulae=(`brew search`)
  11. }
  12. _brew_installed_formulae() {
  13. installed_formulae=(`brew list`)
  14. }
  15. _brew_installed_taps() {
  16. installed_taps=(`brew tap`)
  17. }
  18. _brew_official_taps() {
  19. official_taps=(`brew tap --list-official`)
  20. }
  21. _brew_pinned_taps() {
  22. pinned_taps=(`brew tap --list-pinned`)
  23. }
  24. _brew_outdated_formulae() {
  25. outdated_formulae=(`brew outdated`)
  26. }
  27. _brew_installed_services() {
  28. installed_services=(`brew services list | awk '{print $1}' | tail -n+2`)
  29. }
  30. local -a _1st_arguments
  31. _1st_arguments=(
  32. 'audit:check formulae for Homebrew coding style'
  33. 'cat:display formula file for a formula'
  34. 'cleanup:uninstall unused and old versions of packages'
  35. 'commands:show a list of commands'
  36. 'config:show homebrew and system configuration'
  37. 'create:create a new formula'
  38. 'deps:list dependencies and dependants of a formula'
  39. 'desc:display a description of a formula'
  40. 'doctor:audits your installation for common issues'
  41. 'edit:edit a formula'
  42. 'fetch:download formula resources to the cache'
  43. 'gist-logs:generate a gist of the full build logs'
  44. 'home:visit the homepage of a formula or the brew project'
  45. 'info:information about a formula'
  46. 'install:install a formula'
  47. 'reinstall:install a formula anew; re-using its current options'
  48. 'leaves:show installed formulae that are not dependencies of another installed formula'
  49. 'link:link a formula'
  50. 'linkapps:symlink .app bundles provided by formulae into /Applications'
  51. 'list:list files in a formula or not-installed formulae'
  52. 'log:git commit log for a formula'
  53. 'missing:check all installed formuale for missing dependencies.'
  54. 'migrate:migrate renamed formula to new name'
  55. 'outdated:list formulae for which a newer version is available'
  56. 'pin:pin specified formulae'
  57. 'postinstall:perform post_install for a given formula'
  58. 'prune:remove dead links'
  59. 'remove:remove a formula'
  60. 'search:search for a formula (/regex/ or string)'
  61. 'services:manage services'
  62. 'switch:switch between different versions of a formula'
  63. 'tap:tap a new formula repository from GitHub, or list existing taps'
  64. 'tap-info:information about a tap'
  65. 'tap-pin:pin a tap'
  66. 'tap-unpin:unpin a tap'
  67. 'test-bot:test a formula and build a bottle'
  68. 'uninstall:uninstall a formula'
  69. 'unlink:unlink a formula'
  70. 'unlinkapps:remove symlinked .app bundles provided by formulae from /Applications'
  71. 'unpin:unpin specified formulae'
  72. 'untap:remove a tapped repository'
  73. 'update:fetch latest version of Homebrew and all formulae'
  74. 'upgrade:upgrade outdated formulae'
  75. 'uses:show formulae which depend on a formula'
  76. `brew commands --quiet --include-aliases`
  77. )
  78. local expl
  79. local -a formulae installed_formulae installed_taps official_taps outdated_formulae installed_services
  80. _arguments \
  81. '(-v)-v[verbose]' \
  82. '(--cellar)--cellar[brew cellar]' \
  83. '(--env)--env[brew environment]' \
  84. '(--repository)--repository[brew repository]' \
  85. '(--version)--version[version information]' \
  86. '(--prefix)--prefix[where brew lives on this system]' \
  87. '(--cache)--cache[brew cache]' \
  88. '*:: :->subcmds' && return 0
  89. if (( CURRENT == 1 )); then
  90. _describe -t commands "brew subcommand" _1st_arguments
  91. return
  92. fi
  93. case "$words[1]" in
  94. install|reinstall|audit|home|homepage|log|info|abv|uses|cat|deps|desc|edit|options|switch)
  95. _brew_all_formulae
  96. _wanted formulae expl 'all formulae' compadd -a formulae ;;
  97. linkapps|unlinkapps)
  98. _arguments \
  99. '(--local)--local[operate on ~/Applications instead of /Applications]' \
  100. '1: :->forms' && return 0
  101. if [[ "$state" == forms ]]; then
  102. _brew_installed_formulae
  103. _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae
  104. fi ;;
  105. list|ls)
  106. _arguments \
  107. '(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \
  108. '(--pinned)--pinned[list all versions of pinned formulae]' \
  109. '(--versions)--versions[list all installed versions of a formula]' \
  110. '1: :->forms' && return 0
  111. if [[ "$state" == forms ]]; then
  112. _brew_installed_formulae
  113. _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae
  114. fi ;;
  115. remove|rm|uninstall|unlink|cleanup|link|ln|pin|unpin)
  116. _brew_installed_formulae
  117. _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;;
  118. search|-S)
  119. _arguments \
  120. '(--macports)--macports[search the macports repository]' \
  121. '(--fink)--fink[search the fink repository]' ;;
  122. untap|tap-info|tap-pin)
  123. _brew_installed_taps
  124. _wanted installed_taps expl 'installed taps' compadd -a installed_taps ;;
  125. tap)
  126. _brew_official_taps
  127. _wanted official_taps expl 'official taps' compadd -a official_taps ;;
  128. tap-unpin)
  129. _brew_pinned_taps
  130. _wanted pinned_taps expl 'pinned taps' compadd -a pinned_taps ;;
  131. upgrade)
  132. _brew_outdated_formulae
  133. _wanted outdated_formulae expl 'outdated formulae' compadd -a outdated_formulae ;;
  134. services)
  135. _arguments -C \
  136. '1: :->command' \
  137. '2: :->service' && return 0
  138. local -a commands
  139. commands=(
  140. 'cleanup:Get rid of stale services and unused plists'
  141. 'list:List all services managed by brew services'
  142. 'restart:Gracefully restart selected service'
  143. 'start:Start selected service'
  144. 'stop:Stop selected service'
  145. )
  146. case $state in
  147. command)
  148. _describe -t commands 'Action' commands
  149. ;;
  150. service)
  151. _brew_installed_services
  152. _describe -t subcommands 'Services' installed_services
  153. ;;
  154. esac
  155. esac