about summary refs log tree commit diff
path: root/Completion/Debian
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Debian')
-rw-r--r--Completion/Debian/_apt2
-rw-r--r--Completion/Debian/_deb_packages58
2 files changed, 55 insertions, 5 deletions
diff --git a/Completion/Debian/_apt b/Completion/Debian/_apt
index 169b5f5f7..66129c949 100644
--- a/Completion/Debian/_apt
+++ b/Completion/Debian/_apt
@@ -75,7 +75,7 @@ _apt_arguments () {
   nul=$'\0'
   qnul="\$'\\0'"
 
-  comp_bool='_wanted values && compadd "$expl_bool[@]" '"$bool"
+  comp_bool='_wanted values expl_bool "boolean value" compadd "$expl_bool[@]" '"$bool"
   comp_intlevel= #"_message 'intlevel'"
   comp_configfile='_files "$expl_configfile[@]"'
   comp_arbitem= #"_message 'Foo::Bar=bar'"
diff --git a/Completion/Debian/_deb_packages b/Completion/Debian/_deb_packages
index b5e4ffd85..7973d9868 100644
--- a/Completion/Debian/_deb_packages
+++ b/Completion/Debian/_deb_packages
@@ -1,7 +1,57 @@
 #autoload
 
-if (( ! $+_deb_packages )); then
-  _deb_packages=( $(awk '/^Package:/ { print $2 }' /var/lib/dpkg/status) )
-fi
+# Usage: _deb_packages expl... avail|installed|uninstalled
 
-compadd "$@" - $_deb_packages
+_deb_packages_update_avail () {
+  if (( ! $+_deb_packages_cache_avail )); then
+    _deb_packages_cache_avail=(
+      ${(f)"$(apt-cache dumpavail | awk '/^Package:/ { print $2 }')"}
+    )
+  fi
+  cachevar=_deb_packages_cache_avail
+}
+
+_deb_packages_update_installed () {
+  if (( ! $+_deb_packages_cache_installed )); then
+    _deb_packages_cache_installed=(
+      ${${${(f)"$(dpkg --get-selections)"}:#*deinstall}%%	*}
+    )
+  fi
+  cachevar=_deb_packages_cache_installed
+}
+
+_deb_packages_update_uninstalled () {
+  _deb_packages_update_avail
+  _deb_packages_update_installed
+  if (( ! $+_deb_packages_cache_uninstalled )); then
+    _deb_packages_cache_uninstalled=(
+      ${_deb_packages_cache_avail:#${(j:|:)~${_deb_packages_cache_installed:q}}}
+    )
+  fi
+  cachevar=_deb_packages_cache_uninstalled
+}
+
+_deb_packages () {
+  local command="$argv[$#]" expl cachevar pkgset
+
+  [[ "$command" = (installed|uninstalled|avail) ]] || {
+    _message "_deb_packages:unknown command: $command"
+    return
+  }
+
+  zstyle -s ":completion:${curcontext}:" packageset pkgset
+
+  [[ "$pkgset" = (installed|uninstalled|avail|available) ]] || {
+    pkgset="$command"
+  }
+
+  [[ "$pkgset" = "available" ]] && pkgset="avail"
+
+  expl=("${(@)argv[1,-2]}")
+
+  _deb_packages_update_$pkgset
+
+  _tags packages && compadd "$expl[@]" - "${(@P)cachevar}"
+}
+
+_deb_packages "$@"