_pip 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. 'show:show information about installed packages'
  20. 'install:install packages'
  21. 'search:search PyPI'
  22. 'uninstall:uninstall packages'
  23. 'unzip:unzip individual packages'
  24. 'zip:zip individual packages'
  25. )
  26. local expl
  27. local -a all_pkgs installed_pkgs
  28. _arguments \
  29. '(--version)--version[show version number of program and exit]' \
  30. '(-h --help)'{-h,--help}'[show help]' \
  31. '(-E --environment)'{-E,--environment}'[virtualenv environment to run pip in]' \
  32. '(-s --enable-site-packages)'{-s,--enable-site-packages}'[include site-packages in virtualenv]' \
  33. '(-v --verbose)'{-v,--verbose}'[give more output]' \
  34. '(-q --quiet)'{-q,--quiet}'[give less output]' \
  35. '(--log)--log[log file location]' \
  36. '(--proxy)--proxy[proxy in form user:passwd@proxy.server:port]' \
  37. '(--timeout)--timeout[socket timeout (default 15s)]' \
  38. '*:: :->subcmds' && return 0
  39. if (( CURRENT == 1 )); then
  40. _describe -t commands "pip subcommand" _1st_arguments
  41. return
  42. fi
  43. case "$words[1]" in
  44. search)
  45. _arguments \
  46. '(--index)--index[base URL of Python Package Index]' ;;
  47. freeze)
  48. _arguments \
  49. '(-l --local)'{-l,--local}'[report only virtualenv packages]' ;;
  50. install)
  51. _arguments \
  52. '(-U --upgrade)'{-U,--upgrade}'[upgrade all packages to the newest available version]' \
  53. '(-f --find-links)'{-f,--find-links}'[URL for finding packages]' \
  54. '(--no-deps --no-dependencies)'{--no-deps,--no-dependencies}'[iIgnore package dependencies]' \
  55. '(--no-install)--no-install[only download packages]' \
  56. '(--no-download)--no-download[only install downloaded packages]' \
  57. '(--install-option)--install-option[extra arguments to be supplied to the setup.py]' \
  58. '(--single-version-externally-managed)--single-version-externally-managed[do not download/install dependencies. requires --record or --root]'\
  59. '(--root)--root[treat this path as a fake chroot, installing into it. implies --single-version-externally-managed]'\
  60. '(--record)--record[file to record all installed files to.]'\
  61. '(-r --requirement)'{-r,--requirement}'[requirements file]: :_files'\
  62. '(-e --editable)'{-e,--editable}'[path of or url to source to link to instead of installing.]: :_files -/'\
  63. '1: :->packages' && return 0
  64. if [[ "$state" == packages ]]; then
  65. _pip_all
  66. _wanted piplist expl 'packages' compadd -a piplist
  67. fi ;;
  68. uninstall)
  69. _pip_installed
  70. _wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;;
  71. show)
  72. _pip_installed
  73. _wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;;
  74. esac