about summary refs log tree commit diff
path: root/Completion/Debian
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2016-09-17 09:44:00 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2016-09-18 06:20:59 +0000
commitf0c804879b97190e042eba7f00bc2fcad4841e36 (patch)
treeea8ee72e13b261dea04ebf5de941826169d46dc2 /Completion/Debian
parent7a34c1ad17ec292a54cfa7f653e03b2310020b02 (diff)
downloadzsh-f0c804879b97190e042eba7f00bc2fcad4841e36.tar.gz
zsh-f0c804879b97190e042eba7f00bc2fcad4841e36.tar.xz
zsh-f0c804879b97190e042eba7f00bc2fcad4841e36.zip
39374: _apt: Complete package versions in the 'packagename=<version>' syntax.
Diffstat (limited to 'Completion/Debian')
-rw-r--r--Completion/Debian/Command/_apt41
1 files changed, 40 insertions, 1 deletions
diff --git a/Completion/Debian/Command/_apt b/Completion/Debian/Command/_apt
index a46c3264a..d92d2f884 100644
--- a/Completion/Debian/Command/_apt
+++ b/Completion/Debian/Command/_apt
@@ -464,7 +464,11 @@ _apt-get () {
     \( \
     /$'install\0'\|$'download\0'\|$'source\0'\|$'build-dep\0'/ \
       /$'[^\0]#\0'/ ':packages::_deb_packages "$expl_packages[@]" avail' \# \
-    /$'[^\0/]#/'/ /$'[^\0/]#\0'/ ':release name::_apt_releases' \) \| \
+       \( \
+       /$'[^\0/]#/'/ /$'[^\0/]#\0'/ ':release name::_apt_releases' \| \
+       /$'[^\0=]#='/ /$'[^\0=]#\0'/ ':package version::_apt_versions_of_binary_package' \
+       \)  \
+    \) \| \
     /$'remove\0'/ /$'[^\0]#\0'/ ':packages::_deb_packages "$expl_packages[@]" installed' \# \| \
     /$'purge\0'/ /$'[^\0]#\0'/ ':packages::_deb_packages "$expl_packages[@]" installed' \# \| \
     /$'dist-upgrade\0'/ \| \
@@ -614,6 +618,41 @@ _apt_releases () {
   _tags apt-releases && compadd -a _apt_releases
 }
 
+# Complete versions of the package named in $match[1].
+#
+# Interpret the package name as a binary package (even if there is
+# a source package by that name, too).
+_apt_versions_of_binary_package() {
+  local package_name=${match[1]%=} # $match was set by _regex_arguments
+  local line
+  local name version source
+  local -a kv
+
+  for line in ${(f)"$(_call_program versions-of-package "apt-cache madison $package_name")"}; do
+    # If $package_name is a source package name, we'll have lines of the form
+    #   $package_name | $version | ...Sources
+    #
+    # If $package_name is a binary package name, we'll have lines of the form
+    #   $package_name | $version | ...Packages
+    #   $src_package_name | $version | ...Sources
+    for name version source in "${(@s. | .)line}"; do
+      # Remove leading/trailing whitespace
+      name=${name// }
+      version=${version// }
+      source=${${source# ##}% ##}
+
+      # Skip source packages
+      if [[ $name != $package_name ]] || [[ $source != *Packages* ]]; then
+        continue
+      fi
+
+      kv+=( "${version//:/\\:}:$source" )
+    done
+  done
+
+  _describe -t apt-package-versions "package versions" kv "$@"
+}
+
 _apt_caching_policy () {
   local -a oldp