From 5fcfd1f07e71f24d4a43cac970ec39b514154d69 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Fri, 3 Sep 1999 23:19:14 +0000 Subject: zsh-workers/7641 --- Completion/Debian/_apt-get | 59 ++++++++++++++++++++++++++--------------- Completion/Debian/_deb_packages | 26 +++++++++++++++--- 2 files changed, 61 insertions(+), 24 deletions(-) diff --git a/Completion/Debian/_apt-get b/Completion/Debian/_apt-get index 90e777246..12ab30bc7 100644 --- a/Completion/Debian/_apt-get +++ b/Completion/Debian/_apt-get @@ -1,23 +1,40 @@ #compdef apt-get -_arguments -s \ - -{,-no-}d --{,no-}download-only \ - -{,-no-}f --{,no-}fix-broken \ - -{,-no-}h --{,no-}help \ - -{,-no-}v --{,no-}version \ - -{,-no-}m --{,no-}ignore-missing \ - --{,no-}fix-missing \ - --{,no-}no-download \ - \*-{,-no-}q \*--{,no-}{quiet,silent} \ - -{,-no-}s --{,no-}{simulate,just-print,dry-run,recon,no-act} \ - -{,-no-}y --{,no-}{yes,assume-yes} \ - -{,-no-}u --{,no-}show-upgraded \ - -{,-no-}b --{,no-}{compile,build} \ - --{,no-}ignore-hold \ - --{,no-}no-upgrade \ - --{,no-}force-yes \ - --{,no-}print-uris \ - {-{,-no-}c,--{,no-}config-file}':Configuration File:_files' \ - {-o,--option}':Foo\:\:Bar=bar:' \ - ':command:(update upgrade dselect-upgrade dist-upgrade install remove source check clean autoclean help)' \ - '*:package:_deb_packages' +_apt-get () { + # This doesn't handle command line of apt completely since command line + # parsing library for apt is too complex to handle by _arguments. + _arguments -s \ + -{,-no-}d --{,no-}download-only \ + -{,-no-}f --{,no-}fix-broken \ + -{,-no-}h --{,no-}help \ + -{,-no-}v --{,no-}version \ + -{,-no-}m --{,no-}ignore-missing \ + --{,no-}fix-missing \ + --{,no-}no-download \ + \*-{,-no-}q \*--{,no-}{quiet,silent} \ + -{,-no-}s --{,no-}{simulate,just-print,dry-run,recon,no-act} \ + -{,-no-}y --{,no-}{yes,assume-yes} \ + -{,-no-}u --{,no-}show-upgraded \ + -{,-no-}b --{,no-}{compile,build} \ + --{,no-}ignore-hold \ + --{,no-}no-upgrade \ + --{,no-}force-yes \ + --{,no-}print-uris \ + {-{,-no-}c,--{,no-}config-file}':Configuration File:_files' \ + {-o,--option}':Foo\:\:Bar=bar:' \ + '*::command and packages:_apt-get_args' +} + +_apt-get_args () { + if (( CURRENT == 1 )); then + compadd "$@" - update upgrade dselect-upgrade dist-upgrade install remove source check clean autoclean help + else + case "$words[1]" in + install) _deb_packages uninstalled "$@";; + remove) _deb_packages installed "$@";; + *) _deb_packages avail "$@";; + esac + fi +} + +_apt-get "$@" diff --git a/Completion/Debian/_deb_packages b/Completion/Debian/_deb_packages index b5e4ffd85..cb74137bf 100644 --- a/Completion/Debian/_deb_packages +++ b/Completion/Debian/_deb_packages @@ -1,7 +1,27 @@ #autoload -if (( ! $+_deb_packages )); then - _deb_packages=( $(awk '/^Package:/ { print $2 }' /var/lib/dpkg/status) ) +# Usage: _deb_packages installed|uninstalled|avail + +if (( ! $+_deb_cache_dpkg_get_selections )); then + _deb_cache_dpkg_get_selections=( + ${(f)"$(dpkg --get-selections)"} + ) + _deb_cache_avail=( + ${(f)"$(apt-cache dumpavail | awk '/^Package:/ { print $2 }')"} + ) + _deb_cache_installed=( + ${${_deb_cache_dpkg_get_selections:#*deinstall}%% *} + ) + _deb_cache_uninstalled=( + ${_deb_cache_avail:#${(j:|:)~${_deb_cache_installed:q}}} + ) fi -compadd "$@" - $_deb_packages +local command="$1" +shift + +case "$command" in + installed) compadd "$@" - $_deb_cache_installed;; + uninstalled) compadd "$@" - $_deb_cache_uninstalled;; + avail) compadd "$@" - $_deb_cache_avail;; +esac -- cgit 1.4.1