_pip 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #compdef pip
  2. #autoload
  3. # pip zsh completion, based on homebrew completion
  4. _pip_all() {
  5. # we cache the list of packages (originally from the macports plugin)
  6. if (( ! $+piplist )); then
  7. echo -n " (caching package index...)"
  8. piplist=($(pip search * | cut -d ' ' -f 1 | tr '[A-Z]' '[a-z]'))
  9. fi
  10. }
  11. _pip_installed() {
  12. installed_pkgs=(`pip freeze | cut -d '=' -f 1`)
  13. }
  14. local -a _1st_arguments
  15. _1st_arguments=(
  16. 'bundle:create pybundles (archives containing multiple packages)'
  17. 'freeze:output all currently installed packages (exact versions) to stdout'
  18. 'help:show available commands'
  19. 'install:install packages'
  20. 'search:search PyPI'
  21. 'uninstall:uninstall packages'
  22. 'unzip:unzip individual packages'
  23. 'zip:zip individual packages'
  24. )
  25. local expl
  26. local -a all_pkgs installed_pkgs
  27. _arguments \
  28. '(--version)--version[show version number of program and exit]' \
  29. '(-h --help)'{-h,--help}'[show help]' \
  30. '(-E --environment)'{-E,--environment}'[virtualenv environment to run pip in]' \
  31. '(-s --enable-site-packages)'{-s,--enable-site-packages}'[include site-packages in virtualenv]' \
  32. '(-v --verbose)'{-v,--verbose}'[give more output]' \
  33. '(-q --quiet)'{-q,--quiet}'[give less output]' \
  34. '(--log)--log[log file location]' \
  35. '(--proxy)--proxy[proxy in form user:passwd@proxy.server:port]' \
  36. '(--timeout)--timeout[socket timeout (default 15s)]' \
  37. '*:: :->subcmds' && return 0
  38. if (( CURRENT == 1 )); then
  39. _describe -t commands "pip subcommand" _1st_arguments
  40. return
  41. fi
  42. case "$words[1]" in
  43. search)
  44. _arguments \
  45. '(--index)--index[base URL of Python Package Index]' ;;
  46. freeze)
  47. _arguments \
  48. '(-l --local)'{-l,--local}'[report only virtualenv packages]' ;;
  49. install)
  50. _arguments \
  51. '(-U --upgrade)'{-U,--upgrade}'[upgrade all packages to the newest available version]' \
  52. '(-f --find-links)'{-f,--find-links}'[URL for finding packages]' \
  53. '(--no-deps --no-dependencies)'{--no-deps,--no-dependencies}'[iIgnore package dependencies]' \
  54. '(--no-install)--no-install[only download packages]' \
  55. '(--no-download)--no-download[only install downloaded packages]' \
  56. '(--install-option)--install-option[extra arguments to be supplied to the setup.py]' \
  57. '1: :->packages' && return 0
  58. if [[ "$state" == packages ]]; then
  59. _pip_all
  60. _wanted piplist expl 'packages' compadd -a piplist
  61. fi ;;
  62. uninstall)
  63. _pip_installed
  64. _wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;;
  65. esac