]> git.saurik.com Git - apt.git/blob - completions/bash/apt
Merge branch 'portability/freebsd'
[apt.git] / completions / bash / apt
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 local GENERIC_APT_GET_OPTIONS='
10 -d --download-only
11 -y --assume-yes
12 --assume-no
13 -u --show-upgraded
14 -m --ignore-missing
15 -t --target-release
16 --download
17 --fix-missing
18 --ignore-hold
19 --upgrade
20 --only-upgrade
21 --allow-change-held-packages
22 --allow-remove-essential
23 --allow-downgrades
24 --print-uris
25 --trivial-only
26 --remove
27 --arch-only
28 --allow-unauthenticated
29 --allow-insecure-repositories
30 --install-recommends
31 --install-suggests
32 --fix-policy
33 '
34
35 # see if the user selected a command already
36 local COMMANDS=(
37 "list"
38 "search"
39 "show" "showsrc"
40 "install" "remove" "purge" "autoremove"
41 "update"
42 "upgrade" "full-upgrade" "dist-upgrade"
43 "edit-sources"
44 "help"
45 "source" "build-dep"
46 "clean" "autoclean"
47 "download" "changelog"
48 "moo"
49 "depends" "rdepends"
50 "policy")
51
52 local command i
53 for (( i=0; i < ${#words[@]}-1; i++ )); do
54 if [[ ${COMMANDS[@]} =~ ${words[i]} ]]; then
55 command=${words[i]}
56 break
57 fi
58 done
59
60 # Complete a -t<SPACE><TAB>
61 case $prev in
62 -t|--target-release)
63 COMPREPLY=( $( compgen -W "$(apt-cache policy | egrep -o 'a=[^,]*|n=[^,]*' | cut -f2- -d= | sort -u)" -- "$cur" ) )
64 return 0
65 ;;
66 esac
67
68 # supported options per command
69 if [[ "$cur" == -* ]]; then
70 case $command in
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
75 --download
76 --fix-missing
77 --fix-policy
78 --ignore-hold
79 --force-yes
80 --trivial-only
81 --reinstall --solver
82 -t --target-release'"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
83 return 0
84 ;;
85 update)
86 COMPREPLY=( $( compgen -W '--list-cleanup
87 --print-uris
88 --allow-insecure-repositories
89 ' -- "$cur" ) )
90 return 0
91 ;;
92 list)
93 COMPREPLY=( $( compgen -W '--installed --upgradable
94 --manual-installed
95 -v --verbose
96 -a --all-versions
97 -t --target-release
98 ' -- "$cur" ) )
99 return 0
100 ;;
101 show)
102 COMPREPLY=( $( compgen -W '-a --all-versions
103 ' -- "$cur" ) )
104 return 0
105 ;;
106 depends|rdepends)
107 COMPREPLY=( $( compgen -W '-i
108 --important
109 --installed
110 --pre-depends
111 --depends
112 --recommends
113 --suggests
114 --replaces
115 --breaks
116 --conflicts
117 --enhances
118 --recurse
119 --implicit' -- "$cur" ) )
120 return 0
121 ;;
122 search)
123 COMPREPLY=( $( compgen -W '
124 -n --names-only
125 -f --full' -- "$cur" ) )
126 return 0
127 ;;
128 showsrc)
129 COMPREPLY=( $( compgen -W '
130 --only-source' -- "$cur" ) )
131 return 0
132 ;;
133 source)
134 COMPREPLY=( $( compgen -W '
135 -s --simulate --dry-run
136 -b --compile --build
137 -P --build-profiles
138 --diff-only --debian-only
139 --tar-only
140 --dsc-only
141 -t --target-release
142 '"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
143 return 0
144 ;;
145 build-dep)
146 COMPREPLY=( $( compgen -W '
147 -a --host-architecture
148 -s --simulate --dry-run
149 -P --build-profiles
150 -t --target-release
151 --purge --solver
152 '"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
153 return 0
154 ;;
155 moo)
156 COMPREPLY=( $( compgen -W '
157 --color
158 ' -- "$cur" ) )
159 return 0
160 ;;
161 clean|autocleean)
162 COMPREPLY=( $( compgen -W '
163 -s --simulate --dry-run
164 ' -- "$cur" ) )
165 return 0
166 ;;
167 esac
168 fi
169
170 # specific command arguments
171 if [[ -n $command ]]; then
172 case $command in
173 remove|purge|autoremove)
174 if [[ -f /etc/debian_version ]]; then
175 # Debian system
176 COMPREPLY=( $( \
177 _xfunc dpkg _comp_dpkg_installed_packages $cur ) )
178 else
179 # assume RPM based
180 _xfunc rpm _rpm_installed_packages
181 fi
182 return 0
183 ;;
184 show|list|download|changelog|depends|rdepends)
185 COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
186 2> /dev/null ) )
187 return 0
188 ;;
189 install)
190 COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
191 2> /dev/null ) )
192 _filedir "*.deb"
193 return 0
194 ;;
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" " ) )
199 return 0
200 ;;
201 edit-sources)
202 COMPREPLY=( $( compgen -W '$( command ls $sourcesdir )' \
203 -- "$cur" ) )
204 return 0
205 ;;
206 moo)
207 COMPREPLY=( $( compgen -W 'moo' \
208 -- "$cur" ) )
209 return 0
210 ;;
211 esac
212 fi
213
214 # no command yet, show what commands we have
215 if [ "$command" = "" ]; then
216 COMPREPLY=( $( compgen -W '${COMMANDS[@]}' -- "$cur" ) )
217 fi
218
219 return 0
220 } &&
221 complete -F _apt apt
222
223 # ex: ts=4 sw=4 et filetype=sh