1 # Debian apt(8) completion -*- shell-script -*-
5 local sourcesdir="/etc/apt/sources.list.d"
6 local cur prev words cword
7 _init_completion || return
9 local GENERIC_APT_GET_OPTIONS='
21 --allow-change-held-packages
22 --allow-remove-essential
28 --allow-unauthenticated
29 --allow-insecure-repositories
35 # see if the user selected a command already
40 "install" "remove" "purge" "autoremove"
42 "upgrade" "full-upgrade" "dist-upgrade"
47 "download" "changelog"
53 for (( i=0; i < ${#words[@]}-1; i++ )); do
54 if [[ ${COMMANDS[@]} =~ ${words[i]} ]]; then
60 # Complete a -t<SPACE><TAB>
63 COMPREPLY=( $( compgen -W "$(apt-cache policy | egrep -o 'a=[^,]*|n=[^,]*' | cut -f2- -d= | sort -u)" -- "$cur" ) )
68 # supported options per command
69 if [[ "$cur" == -* ]]; then
71 install|remove|purge|upgrade|dist-upgrade|full-upgrade|autoremove)
72 COMPREPLY=( $( compgen -W '--show-progress
73 --fix-broken --purge --verbose-versions --auto-remove
74 -s --simulate --dry-run
82 -t --target-release'"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
86 COMPREPLY=( $( compgen -W '--list-cleanup
88 --allow-insecure-repositories
93 COMPREPLY=( $( compgen -W '--installed --upgradable
102 COMPREPLY=( $( compgen -W '-a --all-versions
107 COMPREPLY=( $( compgen -W '-i
119 --implicit' -- "$cur" ) )
123 COMPREPLY=( $( compgen -W '
125 -f --full' -- "$cur" ) )
129 COMPREPLY=( $( compgen -W '
130 --only-source' -- "$cur" ) )
134 COMPREPLY=( $( compgen -W '
135 -s --simulate --dry-run
138 --diff-only --debian-only
142 '"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
146 COMPREPLY=( $( compgen -W '
147 -a --host-architecture
148 -s --simulate --dry-run
152 '"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
156 COMPREPLY=( $( compgen -W '
162 COMPREPLY=( $( compgen -W '
163 -s --simulate --dry-run
170 # specific command arguments
171 if [[ -n $command ]]; then
173 remove|purge|autoremove)
174 if [[ -f /etc/debian_version ]]; then
177 _xfunc dpkg _comp_dpkg_installed_packages $cur ) )
180 _xfunc rpm _rpm_installed_packages
184 show|list|download|changelog|depends|rdepends)
185 COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
190 COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
195 source|build-dep|showsrc|policy)
196 COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
197 2> /dev/null ) $( apt-cache dumpavail | \
198 command grep "^Source: $cur" | sort -u | cut -f2 -d" " ) )
202 COMPREPLY=( $( compgen -W '$( command ls $sourcesdir )' \
207 COMPREPLY=( $( compgen -W 'moo' \
214 # no command yet, show what commands we have
215 if [ "$command" = "" ]; then
216 COMPREPLY=( $( compgen -W '${COMMANDS[@]}' -- "$cur" ) )
223 # ex: ts=4 sw=4 et filetype=sh