| 59 |
- |
1 |
# bash completion for rpm
|
|
|
2 |
|
|
|
3 |
have rpm && {
|
|
|
4 |
# helper functions
|
|
|
5 |
|
|
|
6 |
_rpm_installed_packages()
|
|
|
7 |
{
|
|
|
8 |
local nodig="$1" nosig="$2"
|
|
|
9 |
|
|
|
10 |
if [[ -r /var/log/rpmpkgs && \
|
|
|
11 |
/var/log/rpmpkgs -nt /var/lib/rpm/Packages ]]; then
|
|
|
12 |
# using RHL 7.2 or later - this is quicker than querying the DB
|
|
|
13 |
COMPREPLY=( $( compgen -W "$( sed -ne \
|
|
|
14 |
's|^\([^[:space:]]\{1,\}\)-[^[:space:]-]\{1,\}-[^[:space:]-]\{1,\}\.rpm$|\1|p' \
|
|
|
15 |
/var/log/rpmpkgs )" -- "$cur" ) )
|
|
|
16 |
elif type rpmqpack &>/dev/null ; then
|
|
|
17 |
# SUSE's rpmqpack is faster than rpm -qa
|
|
|
18 |
COMPREPLY=( $( compgen -W '$( rpmqpack )' -- "$cur" ) )
|
|
|
19 |
else
|
|
|
20 |
_rpm_nodigsig
|
|
|
21 |
COMPREPLY=( $( rpm -qa $nodig $nosig --qf='%{NAME} ' "$cur*" ) )
|
|
|
22 |
fi
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
_rpm_groups()
|
|
|
26 |
{
|
|
|
27 |
local IFS=$'\n'
|
|
|
28 |
COMPREPLY=( $( compgen -W "$( rpm -qa $nodig $nosig --queryformat \
|
|
|
29 |
'%{group}\n' )" -- "$cur" ) )
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
_rpm_nodigsig()
|
|
|
33 |
{
|
|
|
34 |
if [[ -z "$nodig" && -z "$nosig" ]]; then
|
|
|
35 |
local rpmver
|
|
|
36 |
|
|
|
37 |
rpmver=$(rpm --version)
|
|
|
38 |
rpmver=${rpmver##* }
|
|
|
39 |
|
|
|
40 |
if [[ "$rpmver" > "4.0.4" ]]; then
|
|
|
41 |
nodig="--nodigest"
|
|
|
42 |
fi
|
|
|
43 |
if [[ "$rpmver" > "4.0.99" ]]; then
|
|
|
44 |
nosig="--nosignature"
|
|
|
45 |
fi
|
|
|
46 |
fi
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
# rpm(8) completion
|
|
|
50 |
#
|
|
|
51 |
_rpm()
|
|
|
52 |
{
|
|
|
53 |
local cur prev opts nodig nosig
|
|
|
54 |
|
|
|
55 |
COMPREPLY=()
|
|
|
56 |
_get_comp_words_by_ref cur prev
|
|
|
57 |
nodig=""
|
|
|
58 |
nosig=""
|
|
|
59 |
_rpm_nodigsig
|
|
|
60 |
|
|
|
61 |
if [ $COMP_CWORD -eq 1 ]; then
|
|
|
62 |
# first parameter on line
|
|
|
63 |
case $cur in
|
|
|
64 |
-b*)
|
|
|
65 |
COMPREPLY=( $( compgen -W '-ba -bb -bc -bi -bl -bp -bs' \
|
|
|
66 |
-- "$cur" ) )
|
|
|
67 |
;;
|
|
|
68 |
-t*)
|
|
|
69 |
COMPREPLY=( $( compgen -W '-ta -tb -tc -ti -tl -tp -ts' \
|
|
|
70 |
-- "$cur" ) )
|
|
|
71 |
;;
|
|
|
72 |
--*)
|
|
|
73 |
COMPREPLY=( $( compgen -W '--help --version --initdb \
|
|
|
74 |
--checksig --recompile --rebuild --resign --addsign \
|
|
|
75 |
--rebuilddb --showrc --setperms --setugids --tarbuild \
|
|
|
76 |
--eval --install --upgrade --query --freshen --erase \
|
|
|
77 |
--verify --querytags --rmsource --rmspec --clean \
|
|
|
78 |
--import' -- "$cur" ) )
|
|
|
79 |
;;
|
|
|
80 |
*)
|
|
|
81 |
COMPREPLY=( $( compgen -W '-b -e -E -F -i -q -t -U -V' \
|
|
|
82 |
-- "$cur" ) )
|
|
|
83 |
;;
|
|
|
84 |
esac
|
|
|
85 |
|
|
|
86 |
return 0
|
|
|
87 |
fi
|
|
|
88 |
|
|
|
89 |
case $prev in
|
|
|
90 |
--dbpath|--excludepath|--prefix|--relocate|--root)
|
|
|
91 |
_filedir -d
|
|
|
92 |
return 0
|
|
|
93 |
;;
|
|
|
94 |
--eval|-E)
|
|
|
95 |
# get a list of macros
|
|
|
96 |
COMPREPLY=( $( compgen -W "$( rpm --showrc | sed -ne \
|
|
|
97 |
's/^-\{0,1\}[0-9]\{1,\}[:=][[:space:]]\{1,\}\([^[:space:](]\{3,\}\).*/%\1/p' )" \
|
|
|
98 |
-- "$cur" ) )
|
|
|
99 |
return 0
|
|
|
100 |
;;
|
|
|
101 |
--pipe)
|
|
|
102 |
_compopt_o_filenames
|
|
|
103 |
COMPREPLY=( $( compgen -c -- "$cur" ) )
|
|
|
104 |
return 0
|
|
|
105 |
;;
|
|
|
106 |
--rcfile)
|
|
|
107 |
_filedir
|
|
|
108 |
return 0
|
|
|
109 |
;;
|
|
|
110 |
--specfile)
|
|
|
111 |
# complete on .spec files
|
|
|
112 |
_filedir spec
|
|
|
113 |
return 0
|
|
|
114 |
;;
|
|
|
115 |
--whatprovides)
|
|
|
116 |
if [[ "$cur" == */* ]]; then
|
|
|
117 |
_filedir
|
|
|
118 |
else
|
|
|
119 |
# complete on capabilities
|
|
|
120 |
local IFS=$'\n'
|
|
|
121 |
COMPREPLY=( $( compgen -W "$( rpm -qa $nodig $nosig \
|
|
|
122 |
--queryformat='%{providename}\n' )" -- "$cur" ) )
|
|
|
123 |
fi
|
|
|
124 |
return 0
|
|
|
125 |
;;
|
|
|
126 |
--whatrequires)
|
|
|
127 |
if [[ "$cur" == */* ]]; then
|
|
|
128 |
_filedir
|
|
|
129 |
else
|
|
|
130 |
# complete on capabilities
|
|
|
131 |
local IFS=$'\n'
|
|
|
132 |
COMPREPLY=( $( compgen -W "$( rpm -qa $nodig $nosig \
|
|
|
133 |
--queryformat='%{requirename}\n' )" -- "$cur" ) )
|
|
|
134 |
fi
|
|
|
135 |
return 0
|
|
|
136 |
;;
|
|
|
137 |
--target)
|
|
|
138 |
COMPREPLY=( $( compgen -W "$( command rpm --showrc | sed -ne \
|
|
|
139 |
's/^\s*compatible\s\s*build\s\s*archs\s*:\s*\(.*\)/\1/ p' )" \
|
|
|
140 |
-- "$cur" ) )
|
|
|
141 |
return 0
|
|
|
142 |
;;
|
|
|
143 |
--define|-D|--fileid|--hdrid|--pkgid)
|
|
|
144 |
# argument required but no completions available
|
|
|
145 |
return 0
|
|
|
146 |
;;
|
|
|
147 |
esac
|
|
|
148 |
|
|
|
149 |
# options common to all modes
|
|
|
150 |
opts="--define --eval --macros --nodigest --nosignature --rcfile \
|
|
|
151 |
--quiet --pipe --verbose"
|
|
|
152 |
|
|
|
153 |
case ${COMP_WORDS[1]} in
|
|
|
154 |
-[iFU]*|--install|--freshen|--upgrade)
|
|
|
155 |
if [[ "$cur" == -* ]]; then
|
|
|
156 |
COMPREPLY=( $( compgen -W "$opts --percent --force \
|
|
|
157 |
--test --replacepkgs --replacefiles --root \
|
|
|
158 |
--excludedocs --includedocs --noscripts --ignorearch \
|
|
|
159 |
--dbpath --prefix --ignoreos --nodeps --allfiles \
|
|
|
160 |
--ftpproxy --ftpport --justdb --httpproxy --httpport \
|
|
|
161 |
--noorder --relocate --badreloc --notriggers \
|
|
|
162 |
--excludepath --ignoresize --oldpackage \
|
|
|
163 |
--queryformat --repackage --nosuggests" -- "$cur" ) )
|
|
|
164 |
else
|
|
|
165 |
_filedir '[rs]pm'
|
|
|
166 |
fi
|
|
|
167 |
;;
|
|
|
168 |
-e|--erase)
|
|
|
169 |
if [[ "$cur" == -* ]]; then
|
|
|
170 |
COMPREPLY=( $( compgen -W "$opts --allmatches \
|
|
|
171 |
--noscripts --notriggers --nodeps --test --repackage" \
|
|
|
172 |
-- "$cur" ) )
|
|
|
173 |
else
|
|
|
174 |
_rpm_installed_packages "$nodig" "$nosig"
|
|
|
175 |
fi
|
|
|
176 |
;;
|
|
|
177 |
-q*|--query)
|
|
|
178 |
# options common to all query types
|
|
|
179 |
opts="$opts --changelog --configfiles --conflicts --docfiles
|
|
|
180 |
--dump --enhances --filesbypkg --filecaps --fileclass
|
|
|
181 |
--filecolor --fileprovide --filerequire --filesbypkg --info
|
|
|
182 |
--list --obsoletes --pipe --provides --queryformat --rcfile
|
|
|
183 |
--requires --scripts --suggests --triggers --xml"
|
|
|
184 |
|
|
|
185 |
if [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then
|
|
|
186 |
# -qf completion
|
|
|
187 |
if [[ "$cur" == -* ]]; then
|
|
|
188 |
COMPREPLY=( $( compgen -W "$opts --dbpath --fscontext \
|
|
|
189 |
--last --root --state" -- "$cur" ) )
|
|
|
190 |
else
|
|
|
191 |
_filedir
|
|
|
192 |
fi
|
|
|
193 |
elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then
|
|
|
194 |
# -qg completion
|
|
|
195 |
_rpm_groups
|
|
|
196 |
elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then
|
|
|
197 |
# -qp; uninstalled package completion
|
|
|
198 |
if [[ "$cur" == -* ]]; then
|
|
|
199 |
COMPREPLY=( $( compgen -W "$opts --ftpport --ftpproxy \
|
|
|
200 |
--httpport --httpproxy --nomanifest" -- "$cur" ) )
|
|
|
201 |
else
|
|
|
202 |
_filedir '[rs]pm'
|
|
|
203 |
fi
|
|
|
204 |
else
|
|
|
205 |
# -q; installed package completion
|
|
|
206 |
if [[ "$cur" == -* ]]; then
|
|
|
207 |
COMPREPLY=( $( compgen -W "$opts --all --file --fileid
|
|
|
208 |
--dbpath --fscontext --ftswalk --group --hdrid --last
|
|
|
209 |
--package --pkgid --root --specfile --state
|
|
|
210 |
--triggeredby --whatprovides --whatrequires" \
|
|
|
211 |
-- "$cur" ) )
|
|
|
212 |
elif [[ $COMP_LINE != *\ -@(*([^ -])a|-all )* ]]; then
|
|
|
213 |
_rpm_installed_packages "$nodig" "$nosig"
|
|
|
214 |
fi
|
|
|
215 |
fi
|
|
|
216 |
;;
|
|
|
217 |
-K*|--checksig)
|
|
|
218 |
if [[ "$cur" == -* ]]; then
|
|
|
219 |
COMPREPLY=( $( compgen -W "$opts --nopgp --nogpg --nomd5" \
|
|
|
220 |
-- "$cur" ) )
|
|
|
221 |
else
|
|
|
222 |
_filedir '[rs]pm'
|
|
|
223 |
fi
|
|
|
224 |
;;
|
|
|
225 |
-[Vy]*|--verify)
|
|
|
226 |
if [[ "$cur" == -* ]]; then
|
|
|
227 |
COMPREPLY=( $( compgen -W "$opts --root --dbpath --nodeps \
|
|
|
228 |
--nogroup --nolinkto --nomode --nomtime --nordev --nouser \
|
|
|
229 |
--nofiles --noscripts --nomd5 --querytags --specfile \
|
|
|
230 |
--whatrequires --whatprovides" -- "$cur" ) )
|
|
|
231 |
# check whether we're doing file completion
|
|
|
232 |
elif [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then
|
|
|
233 |
_filedir
|
|
|
234 |
elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then
|
|
|
235 |
_rpm_groups
|
|
|
236 |
elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then
|
|
|
237 |
_filedir '[rs]pm'
|
|
|
238 |
else
|
|
|
239 |
_rpm_installed_packages "$nodig" "$nosig"
|
|
|
240 |
fi
|
|
|
241 |
;;
|
|
|
242 |
-[bt]*)
|
|
|
243 |
if [[ "$cur" == -* ]]; then
|
|
|
244 |
COMPREPLY=( $( compgen -W "$opts --short-circuit --timecheck \
|
|
|
245 |
--clean --rmsource --rmspec --test --sign --buildroot \
|
|
|
246 |
--target --nobuild --nodeps --nodirtokens" -- "$cur" ) )
|
|
|
247 |
elif [[ ${COMP_WORDS[1]} == -b* ]]; then
|
|
|
248 |
_filedir spec
|
|
|
249 |
else
|
|
|
250 |
_filedir '@(t?(ar.)@([gx]z|bz?(2))|tar?(.@(lzma|Z)))'
|
|
|
251 |
fi
|
|
|
252 |
;;
|
|
|
253 |
--rebuild|--recompile)
|
|
|
254 |
if [[ "$cur" == -* ]]; then
|
|
|
255 |
COMPREPLY=( $( compgen -W "$opts --nodeps --rmsource \
|
|
|
256 |
--rmspec --sign --nodirtokens --target" -- "$cur" ) )
|
|
|
257 |
else
|
|
|
258 |
_filedir '@(?(no)src.r|s)pm'
|
|
|
259 |
fi
|
|
|
260 |
;;
|
|
|
261 |
--tarbuild)
|
|
|
262 |
_filedir '@(t?(ar.)@([gx]z|bz?(2))|tar?(.@(lzma|Z)))'
|
|
|
263 |
;;
|
|
|
264 |
--resign|--addsign)
|
|
|
265 |
_filedir '[rs]pm'
|
|
|
266 |
;;
|
|
|
267 |
--setperms|--setgids)
|
|
|
268 |
_rpm_installed_packages "$nodig" "$nosig"
|
|
|
269 |
;;
|
|
|
270 |
--clean|--rmsource|--rmspec)
|
|
|
271 |
if [[ "$cur" == -* ]]; then
|
|
|
272 |
COMPREPLY=( $( compgen -W '--clean --rmsource --rmspec' \
|
|
|
273 |
-- "$cur" ) )
|
|
|
274 |
else
|
|
|
275 |
_filedir spec
|
|
|
276 |
fi
|
|
|
277 |
;;
|
|
|
278 |
--import|--dbpath|--root)
|
|
|
279 |
if [[ "$cur" == -* ]]; then
|
|
|
280 |
COMPREPLY=( $( compgen -W '--import --dbpath --root' \
|
|
|
281 |
-- "$cur" ) )
|
|
|
282 |
else
|
|
|
283 |
_filedir
|
|
|
284 |
fi
|
|
|
285 |
;;
|
|
|
286 |
esac
|
|
|
287 |
|
|
|
288 |
return 0
|
|
|
289 |
}
|
|
|
290 |
complete -F _rpm rpm rpmbuild
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
have gendiff &&
|
|
|
294 |
_gendiff()
|
|
|
295 |
{
|
|
|
296 |
COMPREPLY=()
|
|
|
297 |
local cur prev cword
|
|
|
298 |
_get_comp_words_by_ref cur prev cword
|
|
|
299 |
if [[ $cword -eq 1 ]]; then
|
|
|
300 |
_filedir -d
|
|
|
301 |
elif [[ $prev == *\> ]]; then
|
|
|
302 |
_filedir
|
|
|
303 |
fi
|
|
|
304 |
} &&
|
|
|
305 |
complete -F _gendiff gendiff
|
|
|
306 |
|
|
|
307 |
# Local variables:
|
|
|
308 |
# mode: shell-script
|
|
|
309 |
# sh-basic-offset: 4
|
|
|
310 |
# sh-indent-comment: t
|
|
|
311 |
# indent-tabs-mode: nil
|
|
|
312 |
# End:
|
|
|
313 |
# ex: ts=4 sw=4 et filetype=sh
|