]> git.saurik.com Git - apt.git/blame - completions/bash/apt
The fastest way to get field values is as a range.
[apt.git] / completions / bash / apt
CommitLineData
bd827431
MV
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
5aba1896
JAK
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
bd827431
MV
35 # see if the user selected a command already
36 local COMMANDS=(
37 "list"
38 "search"
5aba1896 39 "show" "showsrc"
bd827431
MV
40 "install" "remove" "purge" "autoremove"
41 "update"
42 "upgrade" "full-upgrade" "dist-upgrade"
43 "edit-sources"
5aba1896
JAK
44 "help"
45 "source" "build-dep"
46 "clean" "autoclean"
47 "download" "changelog"
48 "moo"
49 "depends" "rdepends"
50 "policy")
bd827431
MV
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
5aba1896
JAK
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
bd827431
MV
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
5aba1896 74 -s --simulate --dry-run
bd827431
MV
75 --download
76 --fix-missing
77 --fix-policy
78 --ignore-hold
79 --force-yes
80 --trivial-only
5aba1896
JAK
81 --reinstall --solver
82 -t --target-release'"$GENERIC_APT_GET_OPTIONS" -- "$cur" ) )
bd827431
MV
83 return 0
84 ;;
85 update)
5aba1896
JAK
86 COMPREPLY=( $( compgen -W '--list-cleanup
87 --print-uris
88 --allow-insecure-repositories
bd827431
MV
89 ' -- "$cur" ) )
90 return 0
91 ;;
92 list)
93 COMPREPLY=( $( compgen -W '--installed --upgradable
94 --manual-installed
95 -v --verbose
96 -a --all-versions
5aba1896 97 -t --target-release
bd827431
MV
98 ' -- "$cur" ) )
99 return 0
100 ;;
101 show)
102 COMPREPLY=( $( compgen -W '-a --all-versions
103 ' -- "$cur" ) )
104 return 0
105 ;;
5aba1896
JAK
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 ;;
bd827431
MV
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 ;;
5aba1896 184 show|list|download|changelog|depends|rdepends)
bd827431
MV
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 ;;
5aba1896
JAK
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 ;;
bd827431
MV
201 edit-sources)
202 COMPREPLY=( $( compgen -W '$( command ls $sourcesdir )' \
203 -- "$cur" ) )
204 return 0
205 ;;
5aba1896
JAK
206 moo)
207 COMPREPLY=( $( compgen -W 'moo' \
208 -- "$cur" ) )
209 return 0
210 ;;
bd827431
MV
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} &&
221complete -F _apt apt
222
223# ex: ts=4 sw=4 et filetype=sh