_pip 4.29 KB
Newer Older
1
#compdef pip pip2 pip-2.7 pip3 pip-3.2 pip-3.3 pip-3.4
2
3
#autoload

4
5
# pip zsh completion, based on last stable release (pip8)
# homebrew completion and backwards compatibility
6

7
_pip_all() {
Max Persson's avatar
Max Persson committed
8
9
  # we cache the list of packages (originally from the macports plugin)
  if (( ! $+piplist )); then
10
11
      zsh-pip-cache-packages
      piplist=($(cat $ZSH_PIP_CACHE_FILE))
Max Persson's avatar
Max Persson committed
12
  fi
13
14
}

15
_pip_installed() {
16
  installed_pkgs=(`pip freeze | cut -d '=' -f 1`)
17
18
19
20
}

local -a _1st_arguments
_1st_arguments=(
21
22
23
  'install:install packages'
  'download:download packages'
  'uninstall:uninstall packages'
24
  'freeze:output all currently installed packages (exact versions) to stdout'
25
  'list:list installed packages'
chuancong's avatar
chuancong committed
26
  'show:show information about installed packages'
27
  'search:search PyPI'
28
29
30
31
32
33
  'wheel:build individual wheel archives for your requirements and dependencies'
  'hash:compute a hash of a local package archive'
  'help:show available commands'
  'bundle:create pybundles (archives containing multiple packages)(deprecated)'
  'unzip:unzip individual packages(deprecated)'
  'zip:zip individual packages(deprecated)'
34
35
36
)

local expl
37
local -a all_pkgs installed_pkgs
38
39

_arguments \
40
  '(-h --help)'{-h,--help}'[show help]' \
41
  '(--isolated)--isolated[run pip in isolated mode, ignores environment variables and user configuration]' \
42
  '(-v --verbose)'{-v,--verbose}'[give more output]' \
43
  '(-V --version)'{-V,--version}'[show version number of program and exit]' \
44
45
46
  '(-q --quiet)'{-q,--quiet}'[give less output]' \
  '(--log)--log[log file location]' \
  '(--proxy)--proxy[proxy in form user:passwd@proxy.server:port]' \
47
  '(--retries)--retries[max number of retries per connection (default 5 times)]' \
48
  '(--timeout)--timeout[socket timeout (default 15s)]' \
49
50
51
52
53
54
55
56
57
  '(--exists-action)--exists-action[default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup]' \
  '(--trusted-host)--trusted-host[mark this host as trusted]' \
  '(--cert)--cert[path to alternate CA bundle]' \
  '(--client-cert)--client-cert[path to SSL client certificate]' \
  '(--cache-dir)--cache-dir[store the cache data in specified directory]' \
  '(--no-cache-dir)--no-cache-dir[disable de cache]' \
  '(--disable-pip-version-check)--disable-pip-version-check[do not check periodically for new pip version downloads]' \
  '(-E --environment)'{-E,--environment}'[virtualenv environment to run pip in (deprecated)]' \
  '(-s --enable-site-packages)'{-s,--enable-site-packages}'[include site-packages in virtualenv (deprecated)]' \
58
59
60
61
62
63
64
65
  '*:: :->subcmds' && return 0

if (( CURRENT == 1 )); then
  _describe -t commands "pip subcommand" _1st_arguments
  return
fi

case "$words[1]" in
66
67
68
69
70
71
72
  search)
    _arguments \
      '(--index)--index[base URL of Python Package Index]' ;;
  freeze)
    _arguments \
      '(-l --local)'{-l,--local}'[report only virtualenv packages]' ;;
  install)
73
    _arguments \
74
75
      '(-U --upgrade)'{-U,--upgrade}'[upgrade all packages to the newest available version]' \
      '(-f --find-links)'{-f,--find-links}'[URL for finding packages]' \
76
      '(-r --requirement)'{-r,--requirement}'[Requirements file for packages to install]:File:_files' \
77
78
79
80
      '(--no-deps --no-dependencies)'{--no-deps,--no-dependencies}'[iIgnore package dependencies]' \
      '(--no-install)--no-install[only download packages]' \
      '(--no-download)--no-download[only install downloaded packages]' \
      '(--install-option)--install-option[extra arguments to be supplied to the setup.py]' \
81
82
83
84
85
      '(--single-version-externally-managed)--single-version-externally-managed[do not download/install dependencies. requires --record or --root]'\
      '(--root)--root[treat this path as a fake chroot, installing into it. implies --single-version-externally-managed]'\
      '(--record)--record[file to record all installed files to.]'\
      '(-r --requirement)'{-r,--requirement}'[requirements file]: :_files'\
      '(-e --editable)'{-e,--editable}'[path of or url to source to link to instead of installing.]: :_files -/'\
86
      '1: :->packages' &&  return 0
87

88
89
      if [[ "$state" == packages ]]; then
        _pip_all
Max Persson's avatar
Max Persson committed
90
        _wanted piplist expl 'packages' compadd -a piplist
91
92
93
94
      fi ;;
  uninstall)
    _pip_installed
    _wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;;
chuancong's avatar
chuancong committed
95
96
97
  show)
    _pip_installed
    _wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;;
98
esac