/[soft]/rpm/urpmi/branches/1/urpmi.bash-completion
ViewVC logotype

Contents of /rpm/urpmi/branches/1/urpmi.bash-completion

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3132 - (show annotations) (download)
Wed Feb 29 23:59:36 2012 UTC (8 years, 4 months ago) by tv
File size: 7473 byte(s)
branch

1 # bash completion for urpmi and friends
2 # Copyright (c) 2002-2006 Guillaume Rousse <guillomovitch@mandriva.com>
3 # $Id: urpmi.bash-completion 266536 2010-02-26 21:07:37Z guillomovitch $
4
5 common_options="-q --quiet -v --verbose --debug -h --help --urpmi-root --wait-lock"
6
7 # utility functions
8 _urpmi_get_medias()
9 {
10 medias=( $( urpmq --list-media $1 2>/dev/null | sed -e 's/(/\\(/g' -e 's/)/\\)/g' -e 's/ /\\ /g' ) )
11 }
12
13 _urpmi_medias()
14 {
15 # return list of available media
16 local medias IFS=$'\t\n'
17 # get medias list
18 _urpmi_get_medias all
19 # return matching ones
20 COMPREPLY=( $( compgen -W '${medias[@]}' -- $cur ) )
21 }
22
23 _urpmi_aliases()
24 {
25 # return list of available aliases
26 COMPREPLY=( $( awk -F: '{print $1}' /etc/urpmi/parallel.cfg 2>/dev/null | grep "^${cur//\\\\/}" ) )
27 }
28
29 _urpmi_packages()
30 {
31 local options
32
33 # find media selection options
34 for (( i=1; i < COMP_CWORD; i++ )); do
35 case "${COMP_WORDS[i]}" in
36 --@\(excludemedia|media\))
37 options="$options ${COMP_WORDS[i]} ${COMP_WORDS[i+1]}"
38 i=$(($i+1))
39 ;;
40 --update)
41 options="$options ${COMP_WORDS[i]}"
42 ;;
43 esac
44 done
45
46 COMPREPLY=( $( compgen -W "$(urpmq $options --list)" -- $cur ) )
47 }
48
49 # urpmi completion
50 #
51 _urpmi()
52 {
53 local cur prev options
54
55 COMPREPLY=()
56 cur=`_get_cword`
57 prev=`_get_pword`
58
59 case "$prev" in
60 --media)
61 _urpmi_medias
62 return 0
63 ;;
64 --excludemedia)
65 _urpmi_medias
66 return 0
67 ;;
68 --sortmedia)
69 _urpmi_medias
70 return 0
71 ;;
72 --parallel)
73 _urpmi_aliases
74 return 0
75 ;;
76 --root|--urpmi-root)
77 _filedir -d
78 return 0
79 ;;
80 esac
81
82 if [[ "$cur" == -* ]]; then
83 # return list of available options
84 options="$common_options -a -p -P -y --update --media \
85 --excludemedia --sortmedia --synthesis --auto \
86 --auto-select --no-uninstall --split-level \
87 --split-length --fuzzy --buildrequires --install-src --clean \
88 --noclean --parallel --wget --prozilla --curl \
89 --limit-rate --proxy --proxy-user --bug \
90 --no-verify-rpm --no-install --test --excludepath \
91 --excludedocs --searchmedia --ignoresize --ignorearch \
92 --strict-arch --wget-options --curl-options \
93 --prozilla-options --rsync-options --resume --retry \
94 --skip --prefer --nolock --more-choices"
95 # add dangereous option for everything else as rurpmi
96 if [[ ${COMP_WORDS[0]} != *rurpmi ]]; then
97 options="$options --root --use-distrib --env \
98 --auto-orphans --replacepkgs --justdb \
99 --allow-nodeps --allow-force --no-suggests --force \
100 --noscripts --auto-update --keep --nokeep \
101 --verify-rpm"
102 for (( i=1; i < COMP_CWORD; i++ )); do
103 case ${COMP_WORDS[i]} in
104 ----auto-update)
105 options="$options --no-md5sum \
106 --force-key"
107 ;;
108 esac
109 done
110 fi
111 COMPREPLY=( $( compgen -W "$options" -- $cur ) )
112 else
113 if [[ ${COMP_WORDS[0]} == *rurpmi ]]; then
114 # return available packages only
115 _urpmi_packages
116 else
117 # return available packages (unless clearly a file)
118 # and rpm files
119 if [[ "$cur" != */* ]]; then
120 _urpmi_packages
121 fi
122 _filedir '@(rpm|spec)'
123 fi
124 fi
125 }
126 complete -F _urpmi $filenames urpmi gurpmi rurpmi
127
128 # urpmq completion
129 #
130 _urpmq()
131 {
132 local cur prev
133
134 COMPREPLY=()
135 cur=${COMP_WORDS[COMP_CWORD]}
136 prev=${COMP_WORDS[COMP_CWORD-1]}
137
138 case "$prev" in
139 --media)
140 _urpmi_medias
141 return 0
142 ;;
143 --excludemedia)
144 _urpmi_medias
145 return 0
146 ;;
147 --sortmedia)
148 _urpmi_medias
149 return 0
150 ;;
151 --parallel)
152 _urpmi_nodes
153 return 0
154 ;;
155 --list-media)
156 COMPREPLY=( $( compgen -W 'all update active' -- $cur))
157 return 0
158 ;;
159 esac
160
161 if [[ "$cur" == -* ]]; then
162 # return list of available options
163 COMPREPLY=( $( compgen -W "$common_options -d -u -m -a -c -y -s -i -g -p \
164 -r -f -l --update --media --excludemedia \
165 --sortmedia --synthesis --auto-select --auto-orphans \
166 --no-suggests --fuzzy --keep --nokeep \
167 --list --list-url --list-media --list-nodes --list-aliases \
168 --src --sources --provides --requires --obsoletes --suggests --summary --sourcerpm --force --parallel --wget --curl --prozilla \
169 --changelog --conflicts --proxy --proxy-user --env --dump-config \
170 --whatprovides --whatrequires --whatrequires-recursive \
171 --skip --prefer \
172 --use-distrib --searchmedia --ignorearch" -- $cur))
173 else
174 # return rpm files (can't list available packages anymore)
175 _filedir rpm
176 fi
177 }
178 complete -F _urpmq urpmq
179
180 # urpme completion
181 #
182 _urpme()
183 {
184 local cur prev
185
186 COMPREPLY=()
187 cur=${COMP_WORDS[COMP_CWORD]}
188
189 if [[ "$cur" == -* ]]; then
190 # return list of available options
191 COMPREPLY=( $( compgen -W "$common_options -a --auto --test \
192 --auto-orphans --parallel --justdb --noscripts" -- $cur ) )
193 else
194 # return list of available packages
195 _rpm_installed_packages
196 fi
197 }
198 complete -F _urpme urpme
199
200 # urpmf completion
201 #
202 _urpmf()
203 {
204 local cur prev
205
206 COMPREPLY=()
207 cur=${COMP_WORDS[COMP_CWORD]}
208 prev=${COMP_WORDS[COMP_CWORD-1]}
209
210 case "$prev" in
211 --media)
212 _urpmi_medias
213 return 0
214 ;;
215 --excludemedia)
216 _urpmi_medias
217 return 0
218 ;;
219 --sortmedia)
220 _urpmi_medias
221 return 0
222 ;;
223 esac
224
225 if [[ "$cur" == -* ]]; then
226 # return list of available options
227 COMPREPLY=( $( compgen -W "$common_options -i -f -e -a -o -m --update \
228 --media --excludemedia --sortmedia --synthesis --use-distrib \
229 --uniq --name --group --license --size \
230 --epoch --summary --description --sourcerpm --packager\
231 --buildhost --url --provides --requires --suggests --files \
232 --conflicts --obsoletes --env " -- $cur ) )
233 else
234 # return available files
235 _filedir
236 fi
237 }
238 complete -F _urpmf urpmf
239
240 # urpmi.update completion
241 #
242 _urpmi_update()
243 {
244 local cur
245
246 COMPREPLY=()
247 cur=${COMP_WORDS[COMP_CWORD]}
248
249 if [[ "$cur" == -* ]]; then
250 # return list of available options
251 COMPREPLY=( $( compgen -W "$common_options -a -f --wget --prozilla \
252 --curl --limit-rate --proxy --proxy-user --update \
253 --ignore --no-ignore \
254 --no-md5sum --force-key --norebuild" \
255 -- $cur))
256 else
257 # return list of available media
258 _urpmi_medias
259 fi
260 }
261 complete -F _urpmi_update urpmi.update
262
263 # urpmi.addmedia completion
264 #
265 _urpmi_addmedia()
266 {
267 local cur i args
268
269 COMPREPLY=()
270 cur=${COMP_WORDS[COMP_CWORD]}
271
272 if [[ "$cur" == -* ]]; then
273 # return list of available options
274 COMPREPLY=( $( compgen -W "$common_options -f --wget --curl --prozilla \
275 --limit-rate --proxy --proxy-user --update --raw \
276 --probe-synthesis --probe-hdlist --probe-rpms --no-probe --distrib \
277 --env --version --arch --virtual --norebuild --nopubkey" -- $cur ) )
278 else
279 # count number of mandatory args given sofar
280 args=$COMP_CWORD
281 for (( i=1; i < COMP_CWORD; i++ )); do
282 if [[ "${COMP_WORDS[i]}" == -* ]]; then
283 args=$(($args-1))
284 fi
285 done
286 case $args in
287 1)
288 # return list of available media
289 _urpmi_medias
290 ;;
291 2)
292 # return list of available protocols
293 COMPREPLY=( $( compgen -W 'file:// http:// \
294 ftp:// removable:// ssh:// \
295 rsync://' -- $cur ) )
296 ;;
297 3)
298 # return word "with"
299 COMPREPLY=( 'with' )
300 ;;
301 esac
302 fi
303 }
304 complete -F _urpmi_addmedia urpmi.addmedia
305
306 # urpmi.removemedia completion
307 #
308 _urpmi_removemedia()
309 {
310 local cur
311
312 COMPREPLY=()
313 cur=${COMP_WORDS[COMP_CWORD]}
314
315 if [[ "$cur" == -* ]]; then
316 # if word begins with a dash, return list of available options
317 COMPREPLY=( $( compgen -W "$common_options -a -y" -- $cur ) )
318 else
319 # elsewhere, return list of available media
320 _urpmi_medias
321 fi
322
323 }
324 complete -F _urpmi_removemedia urpmi.removemedia

  ViewVC Help
Powered by ViewVC 1.1.28