_pip 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #compdef pip pip2 pip-2.7 pip3 pip-3.2 pip-3.3 pip-3.4
  2. #autoload
  3. # pip zsh completion, based on last stable release (pip8)
  4. # homebrew completion and backwards compatibility
  5. _pip_all() {
  6. # we cache the list of packages (originally from the macports plugin)
  7. if (( ! $+piplist )); then
  8. zsh-pip-cache-packages
  9. piplist=($(cat $ZSH_PIP_CACHE_FILE))
  10. fi
  11. }
  12. _pip_installed() {
  13. installed_pkgs=($($service freeze | cut -d '=' -f 1))
  14. }
  15. local -a _1st_arguments
  16. _1st_arguments=(
  17. 'install:install packages'
  18. 'download:download packages'
  19. 'uninstall:uninstall packages'
  20. 'freeze:output all currently installed packages (exact versions) to stdout'
  21. 'list:list installed packages'
  22. 'show:show information about installed packages'
  23. 'search:search PyPI'
  24. 'wheel:build individual wheel archives for your requirements and dependencies'
  25. 'hash:compute a hash of a local package archive'
  26. 'help:show available commands'
  27. 'bundle:create pybundles (archives containing multiple packages)(deprecated)'
  28. 'unzip:unzip individual packages(deprecated)'
  29. 'zip:zip individual packages(deprecated)'
  30. )
  31. local expl
  32. local -a all_pkgs installed_pkgs
  33. _arguments \
  34. '(-h --help)'{-h,--help}'[show help]' \
  35. '(--isolated)--isolated[run pip in isolated mode, ignores environment variables and user configuration]' \
  36. '(-v --verbose)'{-v,--verbose}'[give more output]' \
  37. '(-V --version)'{-V,--version}'[show version number of program and exit]' \
  38. '(-q --quiet)'{-q,--quiet}'[give less output]' \
  39. '(--log)--log[log file location]' \
  40. '(--proxy)--proxy[proxy in form user:passwd@proxy.server:port]' \
  41. '(--retries)--retries[max number of retries per connection (default 5 times)]' \
  42. '(--timeout)--timeout[socket timeout (default 15s)]' \
  43. '(--exists-action)--exists-action[default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup]' \
  44. '(--trusted-host)--trusted-host[mark this host as trusted]' \
  45. '(--cert)--cert[path to alternate CA bundle]' \
  46. '(--client-cert)--client-cert[path to SSL client certificate]' \
  47. '(--cache-dir)--cache-dir[store the cache data in specified directory]' \
  48. '(--no-cache-dir)--no-cache-dir[disable de cache]' \
  49. '(--disable-pip-version-check)--disable-pip-version-check[do not check periodically for new pip version downloads]' \
  50. '(-E --environment)'{-E,--environment}'[virtualenv environment to run pip in (deprecated)]' \
  51. '(-s --enable-site-packages)'{-s,--enable-site-packages}'[include site-packages in virtualenv (deprecated)]' \
  52. '*:: :->subcmds' && return 0
  53. if (( CURRENT == 1 )); then
  54. _describe -t commands "pip subcommand" _1st_arguments
  55. return
  56. fi
  57. case "$words[1]" in
  58. search)
  59. _arguments \
  60. '(--index)--index[base URL of Python Package Index]' ;;
  61. freeze)
  62. _arguments \
  63. '(-l --local)'{-l,--local}'[report only virtualenv packages]' ;;
  64. install)
  65. _arguments \
  66. '(-U --upgrade)'{-U,--upgrade}'[upgrade all packages to the newest available version]' \
  67. '(--user)--user[install packages to user home]' \
  68. '(-f --find-links)'{-f,--find-links}'[URL for finding packages]' \
  69. '(-r --requirement)'{-r,--requirement}'[Requirements file for packages to install]:File:_files' \
  70. '(--no-deps --no-dependencies)'{--no-deps,--no-dependencies}'[iIgnore package dependencies]' \
  71. '(--no-install)--no-install[only download packages]' \
  72. '(--no-download)--no-download[only install downloaded packages]' \
  73. '(--install-option)--install-option[extra arguments to be supplied to the setup.py]' \
  74. '(--single-version-externally-managed)--single-version-externally-managed[do not download/install dependencies. requires --record or --root]'\
  75. '(--root)--root[treat this path as a fake chroot, installing into it. implies --single-version-externally-managed]'\
  76. '(--record)--record[file to record all installed files to.]'\
  77. '(-r --requirement)'{-r,--requirement}'[requirements file]: :_files'\
  78. '(-e --editable)'{-e,--editable}'[path of or url to source to link to instead of installing.]: :_files -/'\
  79. '1: :->packages' && return 0
  80. if [[ "$state" == packages ]]; then
  81. _pip_all
  82. _wanted piplist expl 'packages' compadd -a piplist
  83. _files -g "*.(tar.gz|whl)"
  84. fi ;;
  85. uninstall)
  86. _pip_installed
  87. _wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;;
  88. show)
  89. _pip_installed
  90. _wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;;
  91. esac