_brew 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. 'unlink:unlink a formula'
  47. 'unpin:unpin specified formulae'
  48. 'untap:remove a tapped repository'
  49. 'update:freshen up links'
  50. 'upgrade:upgrade outdated formulae'
  51. 'uses:show formulae which depend on a formula'
  52. )
  53. local -a _service_arguments
  54. _service_arguments=(
  55. 'cleanup:get rid of stale services and unused plists'
  56. 'list:list all services managed by `brew services`'
  57. 'restart:gracefully restart selected service'
  58. 'start:start selected service'
  59. 'stop:stop selected service'
  60. )
  61. local expl
  62. local -a formulae installed_formulae installed_taps outdated_formulae running_services
  63. _arguments \
  64. '(-v)-v[verbose]' \
  65. '(--cellar)--cellar[brew cellar]' \
  66. '(--config)--config[brew configuration]' \
  67. '(--env)--env[brew environment]' \
  68. '(--repository)--repository[brew repository]' \
  69. '(--version)--version[version information]' \
  70. '(--prefix)--prefix[where brew lives on this system]' \
  71. '(--cache)--cache[brew cache]' \
  72. '*:: :->subcmds' && return 0
  73. if (( CURRENT == 1 )); then
  74. _describe -t commands "brew subcommand" _1st_arguments
  75. return
  76. fi
  77. case "$words[1]" in
  78. install|reinstall|audit|home|homepage|log|info|abv|uses|cat|deps|edit|options)
  79. _brew_all_formulae
  80. _wanted formulae expl 'all formulae' compadd -a formulae ;;
  81. list|ls)
  82. _arguments \
  83. '(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \
  84. '(--pinned)--pinned[list all versions of pinned formulae]' \
  85. '(--versions)--versions[list all installed versions of a formula]' \
  86. '1: :->forms' && return 0
  87. if [[ "$state" == forms ]]; then
  88. _brew_installed_formulae
  89. _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae
  90. fi ;;
  91. remove|rm|uninstall|unlink|cleanup|link|ln|pin|unpin)
  92. _brew_installed_formulae
  93. _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;;
  94. search|-S)
  95. _arguments \
  96. '(--macports)--macports[search the macports repository]' \
  97. '(--fink)--fink[search the fink repository]' ;;
  98. services)
  99. if [[ -n "$words[2]" ]]; then
  100. case "$words[2]" in
  101. restart|start|stop)
  102. _brew_running_services
  103. _wanted running_services expl 'running services' compadd -a running_services ;;
  104. esac
  105. else
  106. _describe -t commands "brew services subcommand" _service_arguments
  107. fi ;;
  108. untap)
  109. _brew_installed_taps
  110. _wanted installed_taps expl 'installed taps' compadd -a installed_taps ;;
  111. upgrade)
  112. _brew_outdated_formulae
  113. _wanted outdated_formulae expl 'outdated formulae' compadd -a outdated_formulae ;;
  114. esac