_brew 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #compdef brew
  2. #autoload
  3. # imported from the latest homebrew contributions
  4. _brew_all_formulae() {
  5. formulae=(`brew search`)
  6. }
  7. _brew_installed_formulae() {
  8. installed_formulae=(`brew list`)
  9. }
  10. _brew_installed_taps() {
  11. installed_taps=(`brew tap`)
  12. }
  13. _brew_outdated_formulae() {
  14. outdated_formulae=(`brew outdated`)
  15. }
  16. _brew_running_services() {
  17. running_services=(`brew services list | awk '{print $1}'`)
  18. }
  19. local -a _1st_arguments
  20. _1st_arguments=(
  21. 'audit:check formulae for Homebrew coding style'
  22. 'bundle:look for a Brewfile and run each line as a brew command'
  23. 'cat:display formula file for a formula'
  24. 'cleanup:uninstall unused and old versions of packages'
  25. 'commands:show a list of commands'
  26. 'create:create a new formula'
  27. 'deps:list dependencies and dependants of a formula'
  28. 'doctor:audits your installation for common issues'
  29. 'edit:edit a formula'
  30. 'home:visit the homepage of a formula or the brew project'
  31. 'info:information about a formula'
  32. 'install:install a formula'
  33. 'reinstall:install a formula anew; re-using its current options'
  34. 'link:link a formula'
  35. 'list:list files in a formula or not-installed formulae'
  36. 'log:git commit log for a formula'
  37. 'missing:check all installed formuale for missing dependencies.'
  38. 'outdated:list formulae for which a newer version is available'
  39. 'pin:pin specified formulae'
  40. 'prune:remove dead links'
  41. 'remove:remove a formula'
  42. 'search:search for a formula (/regex/ or string)'
  43. 'server:start a local web app that lets you browse formulae (requires Sinatra)'
  44. 'services:small wrapper around `launchctl` for supported formulae'
  45. 'tap:tap a new formula repository from GitHub, or list existing taps'
  46. 'uninstall:uninstall a formula'
  47. 'unlink:unlink a formula'
  48. 'unpin:unpin specified formulae'
  49. 'untap:remove a tapped repository'
  50. 'update:freshen up links'
  51. 'upgrade:upgrade outdated formulae'
  52. 'uses:show formulae which depend on a formula'
  53. )
  54. local -a _service_arguments
  55. _service_arguments=(
  56. 'cleanup:get rid of stale services and unused plists'
  57. 'list:list all services managed by `brew services`'
  58. 'restart:gracefully restart selected service'
  59. 'start:start selected service'
  60. 'stop:stop selected service'
  61. )
  62. local expl
  63. local -a formulae installed_formulae installed_taps outdated_formulae running_services
  64. _arguments \
  65. '(-v)-v[verbose]' \
  66. '(--cellar)--cellar[brew cellar]' \
  67. '(--config)--config[brew configuration]' \
  68. '(--env)--env[brew environment]' \
  69. '(--repository)--repository[brew repository]' \
  70. '(--version)--version[version information]' \
  71. '(--prefix)--prefix[where brew lives on this system]' \
  72. '(--cache)--cache[brew cache]' \
  73. '*:: :->subcmds' && return 0
  74. if (( CURRENT == 1 )); then
  75. _describe -t commands "brew subcommand" _1st_arguments
  76. return
  77. fi
  78. case "$words[1]" in
  79. install|reinstall|audit|home|homepage|log|info|abv|uses|cat|deps|edit|options)
  80. _brew_all_formulae
  81. _wanted formulae expl 'all formulae' compadd -a formulae ;;
  82. list|ls)
  83. _arguments \
  84. '(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \
  85. '(--pinned)--pinned[list all versions of pinned formulae]' \
  86. '(--versions)--versions[list all installed versions of a formula]' \
  87. '1: :->forms' && return 0
  88. if [[ "$state" == forms ]]; then
  89. _brew_installed_formulae
  90. _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae
  91. fi ;;
  92. remove|rm|uninstall|unlink|cleanup|link|ln|pin|unpin)
  93. _brew_installed_formulae
  94. _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;;
  95. search|-S)
  96. _arguments \
  97. '(--macports)--macports[search the macports repository]' \
  98. '(--fink)--fink[search the fink repository]' ;;
  99. services)
  100. if [[ -n "$words[2]" ]]; then
  101. case "$words[2]" in
  102. restart|start|stop)
  103. _brew_running_services
  104. _wanted running_services expl 'running services' compadd -a running_services ;;
  105. esac
  106. else
  107. _describe -t commands "brew services subcommand" _service_arguments
  108. fi ;;
  109. untap)
  110. _brew_installed_taps
  111. _wanted installed_taps expl 'installed taps' compadd -a installed_taps ;;
  112. upgrade)
  113. _brew_outdated_formulae
  114. _wanted outdated_formulae expl 'outdated formulae' compadd -a outdated_formulae ;;
  115. esac