_brew 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #compdef brew
  2. # Brew ZSH completion function
  3. # Drop this somewhere in your $fpath (like /usr/share/zsh/site-functions)
  4. # and rename it _brew
  5. #
  6. # altered from _fink
  7. _brew_all_formulae() {
  8. formulae=(`brew search`)
  9. }
  10. _brew_installed_formulae() {
  11. installed_formulae=(`brew list`)
  12. }
  13. local -a _1st_arguments
  14. _1st_arguments=(
  15. 'install:install a formula'
  16. 'remove:remove a formula'
  17. 'search:search for a formula (/regex/ or string)'
  18. 'list:list files in a formula or not-installed formulae'
  19. 'link:link a formula'
  20. 'unlink:unlink a formula'
  21. 'home:visit the homepage of a formula or the brew project'
  22. 'info:information about a formula'
  23. 'prune:remove dead links'
  24. 'update:freshen up links'
  25. 'log:git commit log for a formula'
  26. 'create:create a new formula'
  27. 'edit:edit a formula'
  28. )
  29. local expl
  30. local -a formula installed_formulae
  31. _arguments \
  32. '(-v --verbose)'{-v,--verbose}'[verbose]' \
  33. '(--version)--version[version information]' \
  34. '(--prefix)--prefix[where brew lives on this system]' \
  35. '(--cache)--cache[brew cache]' \
  36. '*:: :->subcmds' && return 0
  37. if (( CURRENT == 1 )); then
  38. _describe -t commands "brew subcommand" _1st_arguments
  39. return
  40. fi
  41. case "$words[1]" in
  42. list)
  43. _arguments \
  44. '(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \
  45. '1: :->forms' && return 0
  46. if [[ "$state" == forms ]]; then
  47. _brew_installed_formulae
  48. _requested installed_formulae expl 'installed formulae' compadd -a installed_formulae
  49. fi ;;
  50. install|home|log|info)
  51. _brew_all_formulae
  52. _wanted formulae expl 'all formulae' compadd -a formulae ;;
  53. remove|edit|xo)
  54. _brew_installed_formulae
  55. _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;;
  56. esac