_pip 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. zsh-pip-cache-packages
  8. piplist=($(cat $ZSH_PIP_CACHE_FILE))
  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. '(--single-version-externally-managed)--single-version-externally-managed[do not download/install dependencies. requires --record or --root]'\
  58. '(--root)--root[treat this path as a fake chroot, installing into it. implies --single-version-externally-managed]'\
  59. '(--record)--record[file to record all installed files to.]'\
  60. '(-r --requirement)'{-r,--requirement}'[requirements file]: :_files'\
  61. '(-e --editable)'{-e,--editable}'[path of or url to source to link to instead of installing.]: :_files -/'\
  62. '1: :->packages' && return 0
  63. if [[ "$state" == packages ]]; then
  64. _pip_all
  65. _wanted piplist expl 'packages' compadd -a piplist
  66. fi ;;
  67. uninstall)
  68. _pip_installed
  69. _wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;;
  70. esac