about summary refs log tree commit diff
path: root/Completion/Debian/_deb_packages
blob: dd39d055dcee1f36a46315116606a3a555723e58 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#autoload

# 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

local command="$1" expl
shift

_wanted packages expl packages &&
    case "$command" in
    installed) compadd "$@" - $_deb_cache_installed;;
    uninstalled) compadd "$@" - $_deb_cache_uninstalled;;
    avail) compadd "$@" - $_deb_cache_avail;;
    esac