shosei

zsh_brew_completions

May 10th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.62 KB | None | 0 0
  1. #compdef brew
  2. # ------------------------------------------------------------------------------
  3. # Description
  4. # -----------
  5. #
  6. #  Completion script for brew (https://github.com/mxcl/homebrew).
  7. #
  8. #  Source: https://github.com/mxcl/homebrew/blob/master/Library/Contributions/brew_zsh_completion.zsh
  9. #
  10. # ------------------------------------------------------------------------------
  11. # Authors
  12. # -------
  13. #
  14. #  * kulakowski (https://github.com/kulakowski)
  15. #  * Gabe Berke-Williams (https://github.com/gabebw)
  16. #  * James Conroy-Finn (https://github.com/jcf)
  17. #  * Daniel Schauenberg (https://github.com/mrtazz)
  18. #  * Adam Vandenberg (https://github.com/adamv)
  19. #  * Erik Kastner (https://github.com/kastner)
  20. #
  21. # ------------------------------------------------------------------------------
  22. # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
  23. # vim: ft=zsh sw=2 ts=2 et
  24. # ------------------------------------------------------------------------------
  25.  
  26.  
  27. _brew_all_formulae() {
  28.   formulae=(`brew search`) # FIXME _call_program should be used here
  29. }
  30.  
  31. _brew_installed_formulae() {
  32.   installed_formulae=(`brew list`) # FIXME _call_program should be used here
  33. }
  34.  
  35. local -a _1st_arguments
  36. _1st_arguments=(
  37.   'cat:display formula file for a formula'
  38.   'cleanup:uninstall unused and old versions of packages'
  39.   'create:create a new formula'
  40.   'deps:list dependencies and dependants of a formula'
  41.   'doctor:audits your installation for common issues'
  42.   'edit:edit a formula'
  43.   'home:visit the homepage of a formula or the brew project'
  44.   'info:information about a formula'
  45.   'install:install a formula'
  46.   'link:link a formula'
  47.   'list:list files in a formula or not-installed formulae'
  48.   'log:git commit log for a formula'
  49.   'missing:check all installed formulae for missing dependencies.'
  50.   'outdated:list formulae for which a newer version is available'
  51.   'prune:remove dead links'
  52.   'remove:remove a formula'
  53.   'search:search for a formula (/regex/ or string)'
  54.   'server:start a local web app that lets you browse formulae (requires Sinatra)'
  55.   'unlink:unlink a formula'
  56.   'update:freshen up links'
  57.   'upgrade:upgrade outdated formulae'
  58.   'uses:show formulae which depend on a formula'
  59. )
  60.  
  61. local expl
  62. local -a formulae installed_formulae
  63.  
  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.  
  75. if (( CURRENT == 1 )); then
  76.   _describe -t commands "brew subcommand" _1st_arguments
  77.   return
  78. fi
  79.  
  80. case "$words[1]" in
  81.   search|-S)
  82.     _arguments \
  83.       '(--macports)--macports[search the macports repository]' \
  84.       '(--fink)--fink[search the fink repository]' ;;
  85.   list|ls)
  86.     _arguments \
  87.       '(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \
  88.       '(--versions)--versions[list all installed versions of a formula]' \
  89.       '1: :->forms' &&  return 0
  90.  
  91.       if [[ "$state" == forms ]]; then
  92.         _brew_installed_formulae
  93.         _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae
  94.       fi ;;
  95.   install|home|homepage|log|info|abv|uses|cat|deps|edit|options)
  96.     _brew_all_formulae
  97.     _wanted formulae expl 'all formulae' compadd -a formulae ;;
  98.   remove|rm|uninstall|unlink|cleanup|link|ln)
  99.     _brew_installed_formulae
  100.     _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;;
  101. esac
Advertisement
Add Comment
Please, Sign In to add comment