Browse code

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

Added brute force package completion to pip plugin

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