2009-06-05 08:38:19 +02:00
# Debian aptitude(1) completion
2009-10-01 20:54:51 +03:00
2011-10-12 00:19:50 +03:00
_have grep-status && {
2009-06-05 08:38:19 +02:00
_comp_dpkg_hold_packages()
{
2009-10-04 19:42:50 +02:00
grep-status -P -e "^$1" -a -FStatus 'hold' -n -s Package
2009-06-05 08:38:19 +02:00
}
} || {
_comp_dpkg_hold_packages()
{
2009-12-15 23:48:10 +02:00
command grep -B 2 'hold' /var/lib/dpkg/status | \
command grep "Package: $1" | cut -d\ -f2
2009-06-05 08:38:19 +02:00
}
}
_aptitude()
{
2011-04-20 14:18:27 +03:00
local cur prev words cword
_init_completion || return
2009-10-04 19:42:50 +02:00
2011-04-20 14:18:27 +03:00
local dashoptions
2009-10-04 19:42:50 +02:00
dashoptions='-S -u -i -h --help --version -s --simulate -d \
--download-only -P --prompt -y --assume-yes -F \
--display-format -O --sort -w --width -f -r -g \
--with-recommends -R -G --without-recommends -t \
--target-release -V --show-versions -D --show-deps\
-Z -v --verbose --purge-unused --schedule-only'
2011-04-20 14:18:27 +03:00
local special i
for (( i=0; i < ${#words[@]}-1; i++ )); do
if [[ ${words[i]} == @(@(|re)install|@(|un)hold|@(|un)markauto|@(dist|full)-upgrade|download|show|forbid-version|purge|remove|changelog|why@(|-not)|keep@(|-all)|build-dep|@(add|remove)-user-tag) ]]; then
special=${words[i]}
2009-10-04 19:42:50 +02:00
fi
#exclude some mutually exclusive options
2011-04-20 14:18:27 +03:00
[[ ${words[i]} == '-u' ]] && dashoptions=${dashoptions/-i}
[[ ${words[i]} == '-i' ]] && dashoptions=${dashoptions/-u}
2009-10-04 19:42:50 +02:00
done
if [[ -n "$special" ]]; then
case $special in
2009-11-22 11:43:26 +01:00
install|hold|markauto|unmarkauto|dist-upgrade|full-upgrade| \
download|show|changelog|why|why-not|build-dep|add-user-tag| \
remove-user-tag)
2009-10-04 19:42:50 +02:00
COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
return 0
;;
2009-11-22 11:43:26 +01:00
purge|remove|reinstall|forbid-version)
2009-10-04 19:42:50 +02:00
COMPREPLY=( $( _comp_dpkg_installed_packages "$cur" ) )
return 0
;;
unhold)
COMPREPLY=( $( _comp_dpkg_hold_packages "$cur" ) )
return 0
;;
esac
fi
case $prev in
# don't complete anything if these options are found
2009-11-22 11:43:26 +01:00
autoclean|clean|forget-new|search|safe-upgrade|upgrade|update|keep-all)
2009-10-04 19:42:50 +02:00
return 0
;;
-S)
_filedir
return 0
;;
2009-11-22 11:43:26 +01:00
-t|--target-release|--default-release)
2009-10-04 19:42:50 +02:00
COMPREPLY=( $( apt-cache policy | \
2009-12-15 23:48:10 +02:00
command grep "release.o=Debian,a=$cur" | \
2009-10-04 19:42:50 +02:00
sed -e "s/.*a=\(\w*\).*/\1/" | uniq 2> /dev/null ) )
return 0
;;
esac
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "$dashoptions" -- "$cur" ) )
else
COMPREPLY=( $( compgen -W 'update upgrade safe-upgrade forget-new \
clean autoclean install reinstall remove \
hold unhold purge markauto unmarkauto why why-not \
dist-upgrade full-upgrade download search show \
2009-10-26 10:19:37 +01:00
forbid-version changelog keep-all build-dep \
add-user-tag remove-user-tag' -- "$cur" ) )
2009-10-04 19:42:50 +02:00
fi
return 0
2011-04-04 22:14:39 +03:00
} &&
2009-10-22 12:04:29 +03:00
complete -F _aptitude -o default aptitude
2009-10-01 20:54:51 +03:00
# Local variables:
# mode: shell-script
2009-10-04 19:42:50 +02:00
# sh-basic-offset: 4
2009-10-01 20:54:51 +03:00
# sh-indent-comment: t
2009-10-04 19:42:50 +02:00
# indent-tabs-mode: nil
2009-10-01 20:54:51 +03:00
# End:
2009-10-04 19:42:50 +02:00
# ex: ts=4 sw=4 et filetype=sh