about summary refs log tree commit diff
path: root/Completion/Debian/_deb_packages
blob: cb74137bf5eefbc7a4c9c7c9067c56ac3411daa1 (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
#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"
shift

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