e25147a3af42503f2ed1c4199f4541314a9e8d34

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #734 from maxpersson/726-pip-completion

Added brute force package completion to pip plugin

Diff

 1diff --git a/plugins/pip/_pip b/plugins/pip/_pip
 2index b58010173a5028b0dc0db651f042e56df861d497..df53ba5ce8ec788d3ff7da94a9936ffee94267db 100644
 3--- a/plugins/pip/_pip
 4+++ b/plugins/pip/_pip
 5@@ -3,30 +3,43 @@
 6 
 7 # pip zsh completion, based on homebrew completion
 8 
 9+_pip_all() {
10+  # we cache the list of packages (originally from the macports plugin)
11+  if (( ! $+piplist )); then
12+    echo -n " (caching package index...)"
13+	piplist=($(pip search * | cut -d ' ' -f 1 | tr '[A-Z]' '[a-z]'))
14+  fi
15+}
16+
17 _pip_installed() {
18-  installed_pkgs=(`pip freeze`)
19+  installed_pkgs=(`pip freeze | cut -d '=' -f 1`)
20 }
21 
22 local -a _1st_arguments
23 _1st_arguments=(
24-  'bundle:Create pybundles (archives containing multiple packages)'
25-  'freeze:Output all currently installed packages (exact versions) to stdout'
26-  'help:Show available commands'
27-  'install:Install packages'
28-  'search:Search PyPI'
29-  'uninstall:Uninstall packages'
30-  'unzip:Unzip individual packages'
31-  'zip:Zip individual packages'
32+  'bundle:create pybundles (archives containing multiple packages)'
33+  'freeze:output all currently installed packages (exact versions) to stdout'
34+  'help:show available commands'
35+  'install:install packages'
36+  'search:search PyPI'
37+  'uninstall:uninstall packages'
38+  'unzip:unzip individual packages'
39+  'zip:zip individual packages'
40 )
41 
42 local expl
43-local -a pkgs installed_pkgs
44+local -a all_pkgs installed_pkgs
45 
46 _arguments \
47-  '(--version)--version[Show version number of program and exit]' \
48-  '(-v --verbose)'{-v,--verbose}'[Give more output]' \
49-  '(-q --quiet)'{-q,--quiet}'[Give less output]' \
50-  '(-h --help)'{-h,--help}'[Show help]' \
51+  '(--version)--version[show version number of program and exit]' \
52+  '(-h --help)'{-h,--help}'[show help]' \
53+  '(-E --environment)'{-E,--environment}'[virtualenv environment to run pip in]' \
54+  '(-s --enable-site-packages)'{-s,--enable-site-packages}'[include site-packages in virtualenv]' \
55+  '(-v --verbose)'{-v,--verbose}'[give more output]' \
56+  '(-q --quiet)'{-q,--quiet}'[give less output]' \
57+  '(--log)--log[log file location]' \
58+  '(--proxy)--proxy[proxy in form user:passwd@proxy.server:port]' \
59+  '(--timeout)--timeout[socket timeout (default 15s)]' \
60   '*:: :->subcmds' && return 0
61 
62 if (( CURRENT == 1 )); then
63@@ -35,10 +48,25 @@ if (( CURRENT == 1 )); then
64 fi
65 
66 case "$words[1]" in
67-  list)
68-      if [[ "$state" == forms ]]; then
69-        _pip_installed
70-        _requested installed_pkgs expl 'installed packages' compadd -a installed_pkgs
71+  search)
72+    _arguments \
73+      '(--index)--index[base URL of Python Package Index]' ;;
74+  freeze)
75+    _arguments \
76+      '(-l --local)'{-l,--local}'[report only virtualenv packages]' ;;
77+  install)
78+  	_arguments \
79+      '(-U --upgrade)'{-U,--upgrade}'[upgrade all packages to the newest available version]' \
80+      '(-f --find-links)'{-f,--find-links}'[URL for finding packages]' \
81+      '(--no-deps --no-dependencies)'{--no-deps,--no-dependencies}'[iIgnore package dependencies]' \
82+      '(--no-install)--no-install[only download packages]' \
83+      '(--no-download)--no-download[only install downloaded packages]' \
84+      '(--install-option)--install-option[extra arguments to be supplied to the setup.py]' \
85+      '1: :->packages' &&  return 0
86+     
87+      if [[ "$state" == packages ]]; then
88+        _pip_all
89+        _wanted piplist expl 'packages' compadd -a piplist
90       fi ;;
91   uninstall)
92     _pip_installed