2009-06-05 08:38:19 +02:00
# Debian aptitude(1) completion
2009-10-01 20:54:51 +03:00
2009-06-05 08:38:19 +02:00
have aptitude && {
have grep-status && {
_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()
{
2009-10-04 19:42:50 +02:00
local cur dashoptions prev special i
COMPREPLY=()
2010-02-08 17:25:08 +01:00
_get_comp_words_by_ref cur prev
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'
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
2009-10-26 09:44:27 +01:00
if [[ ${COMP_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
2009-10-04 19:42:50 +02:00
special=${COMP_WORDS[i]}
fi
#exclude some mutually exclusive options
[[ ${COMP_WORDS[i]} == '-u' ]] && dashoptions=${dashoptions/-i}
[[ ${COMP_WORDS[i]} == '-i' ]] && dashoptions=${dashoptions/-u}
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
2009-06-05 08:38:19 +02:00
}
2009-10-22 12:04:29 +03:00
complete -F _aptitude -o default aptitude
2009-06-05 08:38:19 +02:00
}
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