_pip 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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=(`pip 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. '(-f --find-links)'{-f,--find-links}'[URL for finding packages]' \
  68. '(-r --requirement)'{-r,--requirement}'[Requirements file for packages to install]:File:_files' \
  69. '(--no-deps --no-dependencies)'{--no-deps,--no-dependencies}'[iIgnore package dependencies]' \
  70. '(--no-install)--no-install[only download packages]' \
  71. '(--no-download)--no-download[only install downloaded packages]' \
  72. '(--install-option)--install-option[extra arguments to be supplied to the setup.py]' \
  73. '(--single-version-externally-managed)--single-version-externally-managed[do not download/install dependencies. requires --record or --root]'\
  74. '(--root)--root[treat this path as a fake chroot, installing into it. implies --single-version-externally-managed]'\
  75. '(--record)--record[file to record all installed files to.]'\
  76. '(-r --requirement)'{-r,--requirement}'[requirements file]: :_files'\
  77. '(-e --editable)'{-e,--editable}'[path of or url to source to link to instead of installing.]: :_files -/'\
  78. '1: :->packages' && return 0
  79. if [[ "$state" == packages ]]; then
  80. _pip_all
  81. _wanted piplist expl 'packages' compadd -a piplist
  82. fi ;;
  83. uninstall)
  84. _pip_installed
  85. _wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;;
  86. show)
  87. _pip_installed
  88. _wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;;
  89. esac