1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-11-20 14:04:03 +01:00
zsh/Completion/Debian/_deb_packages

58 lines
1.4 KiB
Plaintext

#autoload
# Usage: _deb_packages expl... avail|installed|uninstalled
_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 "$@"