]> git.saurik.com Git - apt.git/blob - debian/apt.bash-completion
libapt-pkg5.0: Add Breaks appstream (<< 0.9.0-3~)
[apt.git] / debian / apt.bash-completion
1 # Debian apt(8) completion -*- shell-script -*-
2
3 _apt()
4 {
5 local sourcesdir="/etc/apt/sources.list.d"
6 local cur prev words cword
7 _init_completion || return
8
9 # see if the user selected a command already
10 local COMMANDS=(
11 "list"
12 "search"
13 "show"
14 "install" "remove" "purge" "autoremove"
15 "update"
16 "upgrade" "full-upgrade" "dist-upgrade"
17 "edit-sources"
18 "help")
19
20 local command i
21 for (( i=0; i < ${#words[@]}-1; i++ )); do
22 if [[ ${COMMANDS[@]} =~ ${words[i]} ]]; then
23 command=${words[i]}
24 break
25 fi
26 done
27
28 # supported options per command
29 if [[ "$cur" == -* ]]; then
30 case $command in
31 install|remove|purge|upgrade|dist-upgrade|full-upgrade|autoremove)
32 COMPREPLY=( $( compgen -W '--show-progress
33 --fix-broken --purge --verbose-versions --auto-remove
34 --simulate --dry-run
35 --download
36 --fix-missing
37 --fix-policy
38 --ignore-hold
39 --force-yes
40 --trivial-only
41 --reinstall --solver' -- "$cur" ) )
42 return 0
43 ;;
44 update)
45 COMPREPLY=( $( compgen -W '--list-cleanup
46 ' -- "$cur" ) )
47 return 0
48 ;;
49 list)
50 COMPREPLY=( $( compgen -W '--installed --upgradable
51 --manual-installed
52 -v --verbose
53 -a --all-versions
54 ' -- "$cur" ) )
55 return 0
56 ;;
57 show)
58 COMPREPLY=( $( compgen -W '-a --all-versions
59 ' -- "$cur" ) )
60 return 0
61 ;;
62 esac
63 fi
64
65 # specific command arguments
66 if [[ -n $command ]]; then
67 case $command in
68 remove|purge|autoremove)
69 if [[ -f /etc/debian_version ]]; then
70 # Debian system
71 COMPREPLY=( $( \
72 _xfunc dpkg _comp_dpkg_installed_packages $cur ) )
73 else
74 # assume RPM based
75 _xfunc rpm _rpm_installed_packages
76 fi
77 return 0
78 ;;
79 show|list)
80 COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
81 2> /dev/null ) )
82 return 0
83 ;;
84 install)
85 COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
86 2> /dev/null ) )
87 _filedir "*.deb"
88 return 0
89 ;;
90 edit-sources)
91 COMPREPLY=( $( compgen -W '$( command ls $sourcesdir )' \
92 -- "$cur" ) )
93 return 0
94 ;;
95 esac
96 fi
97
98 # no command yet, show what commands we have
99 if [ "$command" = "" ]; then
100 COMPREPLY=( $( compgen -W '${COMMANDS[@]}' -- "$cur" ) )
101 fi
102
103 return 0
104 } &&
105 complete -F _apt apt
106
107 # ex: ts=4 sw=4 et filetype=sh