-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_completion
executable file
·1771 lines (1543 loc) · 43.7 KB
/
.bash_completion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# bash_completion - some programmable completion functions for bash 2.05a
#
# <![CDATA[
#
# $Id: bash_completion,v 1.84 2002/02/04 03:15:42 ianmacd Exp $
#
# Copyright (C) Ian Macdonald <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# RELEASE: 20020204
[ -n "$DEBUG" ] && set -v || set +v
# Alter the following to reflect the location of this file
#
[ -z "$BASH_COMPLETION" ] && declare -r BASH_COMPLETION=~/.bash_completion
# Set a couple of useful vars
#
OS=$( uname -s )
RELEASE=$( uname -r )
# Turn on extended globbing and programmable completion
shopt -s extglob progcomp
# A lot of the following one-liners were taken directly from the
# completion examples provided with the bash 2.04 source distribution
# Make directory commands see only directories
complete -d mkdir rmdir pushd
# the following section lists completions that are redefined later
# START exclude -- do NOT remove this line
complete -f -X '!*.bz2' bunzip2
complete -f -X '!*.+(zip|ZIP|jar|JAR|exe|EXE)' unzip
complete -f -X '*.Z' compress
complete -f -X '!*.+(Z|gz|tgz|Gz|rib)' gunzip zcat zmore
complete -f -X '!*.Z' uncompress
complete -f -X '!*.+(gif|jpg|jpeg|tif|tiff|png|GIF|JPG|TIF|TIFF|PNG|bmp)' ee xv
complete -f -X '!*.+(?(e)ps|?(E)PS|?(e)ps.gz|pdf|PDF)' gv ggv
complete -f -X '!*.+(dvi|DVI)' dvips xdvi dviselect dvitype
complete -f -X '!*.+(pdf|PDF)' acroread xpdf
complete -f -X '!*.texi*' makeinfo texi2dvi texi2html
complete -f -X '!*.+(tex|TEX)' tex latex slitex jadetex pdfjadetex
complete -f -X '!*.+(mp3|MP3)' mpg123
complete -f -X '!*.+(mpg|mpeg|avi|asf|vob|bin|vcd|ps|pes|fli|viv|rm|ram|yuv)' mplayer
complete -f -X '!*.+(avi|asf)' aviplay
complete -f -X '!*.+(rm|ram)' realplay
complete -f -X '!*.+(mpg|mpeg|avi|mov)' xanim
complete -f -X '!*.+(ogg|OGG)' ogg123
complete -f -X '!*.+(mp3|MP3|ogg|OGG|wav|WAV)' xmms gqmpeg freeamp
complete -f -X '!*.mcp' interp fltkinterp
complete -f -X '!*.+(dv|DV|dv.inprogress|DV.inprogress)' playdv
complete -f -X '!*.+(ma|mb)' maya
# FINISH exclude -- do not remove this line
# kill sees only signals
complete -A signal -P '-' kill
# user commands see only users
complete -u finger su usermod userdel passwd
# group commands see only groups
complete -g groupmod groupdel passwd
# bg completes with stopped jobs
complete -A stopped -P '%' bg
# other job commands
complete -j -P '%' fg jobs disown
# network commands complete with hostname
complete -A hostname ssh rsh telnet rlogin ftp ping fping host traceroute \
nslookup
# export and others complete with shell variables
complete -v export local readonly unset
# set completes with set options
complete -A setopt set
# shopt completes with shopt options
complete -A shopt shopt
# helptopics
complete -A helptopic help
# unalias completes with aliases
complete -a unalias
# bind completes with readline bindings (make this more intelligent)
complete -A binding bind
# Now we get to the meat of the file, the functions themselves. Some
# of these are works in progress. Most assume GNU versions of the
# tools in question and may require modifications for use on vanilla
# UNIX systems.
#
# A couple of functions may have non-portable, Linux specific code in
# them, but this will be noted where applicable
# This function is handy for checking whether we have certain programs
# on the system. No need for bulky functions in memory if we don't.
#
have()
{
unset -v have
type $1 &> /dev/null
[ $? = 0 ] && have="yes"
}
# GNU chown(1) completion.
#
_chown()
{
local cur prev user group i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
# do not attempt completion if we're specifying an option
[ "$cur" == -* ] && return 0
# first parameter on line or first since an option?
if [ $COMP_CWORD = 1 ] || [[ "$prev" == -* ]]; then
if [[ "$cur" == [a-zA-Z]*.* ]]; then
user=${cur%.*}
group=${cur#*.}
COMPREPLY=( $( compgen -g $group ) )
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
COMPREPLY[i]=$user.${COMPREPLY[i]}
done
else
COMPREPLY=( $( compgen -u $cur -S '.' ) )
fi
fi
return 0
}
complete -F _chown -o default chown
# chgrp(1) completion
#
_chgrp()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
# do not attempt completion if we're specifying an option
[ "$cur" == -* ] && return 0
# first parameter on line or first since an option?
if [ $COMP_CWORD = 1 ] || [[ "$prev" == -* ]]; then
_expand || return 0
COMPREPLY=( $( compgen -g $cur ) )
fi
return 0
}
complete -F _chgrp -o default chgrp
# umount(8) completion. This relies on the mount point being the third
# space-delimited field in the output of mount(8)
#
_umount()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
# could rewrite the cut | grep to be a sed command, but this is
# clearer and doesn't result in much overhead
COMPREPLY=( $( mount | cut -d' ' -f 3 | grep ^$cur) )
return 0
}
complete -F _umount -o filenames umount
# mount(8) completion. This will pull a list of possible mounts out of
# /etc/fstab, unless the word being completed contains a ':', which
# would indicate the specification of an NFS server. In that case, we
# query the server for a list of all available exports and complete on
# that instead.
#
_mount()
{ local cur i sm
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
for i in {,/usr}/sbin/showmount; do [ -x $i ] && sm=$i && break; done
if [ -n "$sm" ] && [[ "$cur" == *:* ]]; then
COMPREPLY=( $( $sm -e --no-headers ${cur%%:*} | \
grep ^${cur#*:} | awk '{print $1}' ) )
else
COMPREPLY=( $( awk '{if ($2 ~ /\//) print $2}' /etc/fstab | \
grep ^$cur ) )
fi
return 0
}
complete -F _mount -o default mount
# Linux rmmod(1) completion. This completes on a list of all currently
# installed kernel modules.
#
[ $OS = Linux ] &&
_rmmod()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $( /sbin/lsmod | \
awk '{if (NR != 1 && $1 ~ /^'$cur'/) print $1}' ) )
return 0
}
[ $OS = Linux ] && complete -F _rmmod rmmod
# Linux insmod(8) & modprobe(8) completion. This completes on a list of all
# available modules for the version of the kernel currently running.
#
[ $OS = Linux ] &&
_insmod()
{
local cur prev modpath
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
modpath=/lib/modules/`uname -r`
# behave like lsmod for modprobe -r
if [ ${COMP_WORDS[0]} = "modprobe" ] &&
[ "${COMP_WORDS[1]}" = "-r" ]; then
COMPREPLY=( $( /sbin/lsmod | \
awk '{if (NR != 1 && $1 ~ /^'$cur'/) print $1}' ) )
return 0
fi
# do filename completion if we're giving a path to a module
if [[ "$cur" == /* ]]; then
COMPREPLY=( $( compgen -f $cur ) )
return 0
fi
if [ $COMP_CWORD -gt 1 ]; then
# do module parameter completion
COMPREPLY=( $( /sbin/modinfo -p ${COMP_WORDS[1]} | \
awk '{if ($1 ~ /^'$cur'/) print $1}' ) )
else
# do module name completion
COMPREPLY=( $( \ls -R $modpath | \
sed -ne 's/^\('$cur'.*\)\.o$/\1/p') )
fi
return 0
}
[ $OS = Linux ] && complete -F _insmod -o filenames insmod modprobe
# man(1) completion. This is Linux specific, in that 'man <section> <page>'
# is the expected syntax. This allows one to do something like
# 'man 3 str<tab>' to obtain a list of all string handling syscalls on
# the system.
#
[ $OS = Linux ] &&
_man()
{
local cur prev cmd
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
_expand || return 0
# default completion if parameter contains /
[[ "$cur" == */* ]] && return 0
# default to command completion if no man.config
if [ ! -r /etc/man.config ]; then
COMPREPLY=( $( compgen -c $cur ) )
return 0
fi
if [[ "$prev" == [0-9ln] ]]; then
# churn out a string of paths to search, with * appended to $cur
cmd=`awk '{if ($1 ~ /^MANPATH/) \
print $(NF)"/man'$prev'/'$cur'*"}' /etc/man.config | \
sort -u`
# strip off * from paths ending in /*
cmd=${cmd//\/\\*/\/}
# redirect stderr for when path doesn't exist
cmd="ls $cmd 2>/dev/null"
COMPREPLY=( $( eval $cmd ) )
# get basename of man pages
COMPREPLY=( ${COMPREPLY[@]##*/} )
# strip suffix from man pages
COMPREPLY=( ${COMPREPLY[@]%.gz} )
COMPREPLY=( ${COMPREPLY[@]%.*} )
else
cmd=`awk '{if ($1 ~ /^MANPATH/) \
print $(NF)"/man?/'$cur'*"}' /etc/man.config | sort -u`
cmd=${cmd//\/\\*/\/}
cmd="ls $cmd 2>/dev/null"
COMPREPLY=( $( eval $cmd ) )
COMPREPLY=( ${COMPREPLY[@]##*/} )
COMPREPLY=( ${COMPREPLY[@]%.gz} )
COMPREPLY=( ${COMPREPLY[@]%.*} $( compgen -G $cur\*.[0-9ln] ) )
fi
return 0
}
[ $OS = Linux ] && complete -F _man -o default man
# Linux killall(1) completion. This wouldn't be much use on, say,
# Solaris, where killall does exactly that: kills ALL processes.
#
# This could be improved. For example, it currently doesn't take
# command line options into account
#
_killall()
{
local cur prev i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [[ "$prev" == -[A-Z0-9]* ]]; then
# get a list of processes (the sub() in the awk takes care
# of getting the basename of the process, the first sed
# evaluation takes care of swapped out processes, and the
# second takes care of getting the basename of the process)
COMPREPLY=( $( ps ahx | sed -e 's#[]\[()]##g' | \
awk '{p=$5;sub("^.*/","",p);if (p ~ /^'$cur'/) print $5}' | \
sed -e 's#^.*/##' ) )
return 0
fi
# first parameter can be either a signal or a process
if [ $COMP_CWORD = 1 ]; then
# standard signal completion is rather braindead, so we need
# to hack around to get what we want here, which is to
# complete on a dash, followed by the signal name minus
# the SIG prefix
COMPREPLY=( $( compgen -A signal SIG${cur#-} ))
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
COMPREPLY[i]=-${COMPREPLY[i]#SIG}
done
fi
# get processes, adding to signals if applicable
COMPREPLY=( ${COMPREPLY[*]} $( ps ahx | sed -e 's#[]\[()]##g' | \
awk '{p=$5;sub("^.*/","",p);if (p ~ /^'$cur'/) print $5}' | \
sed -e 's#^.*/##' ))
return 0
}
complete -F _killall killall
# GNU find(1) completion. This makes heavy use of ksh style extended
# globs and contains Linux specific code for completing the parameter
# to the -fstype option.
#
_find()
{
local cur ncur prev i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]#}
ncur=${cur#-}
prev=${COMP_WORDS[COMP_CWORD-1]}
case "$prev" in
-@(max|min)depth)
COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9' ) )
return 0
;;
-?(a)newer|-fls|-fprint?(0|f))
COMPREPLY=( $( compgen -f $ncur ) )
return 0
;;
-fstype)
# this is highly non-portable
COMPREPLY=( $( cut -d$'\t' -f 2 /proc/filesystems | grep ^$ncur ) )
return 0
;;
-gid)
COMPREPLY=( $( awk 'BEGIN {FS=":"} \
{if ($3 ~ /^'$ncur'/) print $3}' /etc/group ) )
return 0
;;
-group)
COMPREPLY=( $( compgen -g $ncur ) )
return 0
;;
-?(x)type)
COMPREPLY=( $( compgen -W 'b c d p f l s' $ncur ) )
return 0
;;
-uid)
COMPREPLY=( $( awk 'BEGIN {FS=":"} \
{if ($3 ~ /^'$ncur'/) print $3}' /etc/passwd ) )
return 0
;;
-user)
COMPREPLY=( $( compgen -u $ncur ) )
return 0
;;
-[acm]min|-[acm]time|-?(i)?(l)name|-inum|-?(i)path|-?(i)regex| \
-links|-perm|-size|-used|-exec|-ok|-printf)
# do nothing, just wait for a parameter to be given
return 0
;;
esac
_expand || return 0
# handle case where first parameter is not a dash option
if [ $COMP_CWORD = 1 -a "$cur" = "$ncur" ]; then
COMPREPLY=( $( compgen -d $cur ) )
return 0
fi
# complete using basic options ($ncur has had its dash removed here,
# as otherwise compgen will bomb out with an error, since it thinks
# the dash is an option to itself)
COMPREPLY=( $( compgen -W 'daystart depth follow help maxdepth \
mindepth mount noleaf version xdev amin anewer atime \
cmin cnewer ctime empty false fstype gid group ilname \
iname inum ipath iregex links lname mmin mtime name \
newer nouser nogroup perm regex size true type uid \
used user xtype exec fls fprint fprint0 fprintf ok \
print print0 printf prune ls' $ncur ) )
# this removes any options from the list of completions that have
# already been specified somewhere on the command line.
COMPREPLY=( $( echo "${COMP_WORDS[@]}-" | \
(while read -d '-' i; do
[ "$i" == "" ] && continue
# flatten array with spaces on either side,
# otherwise we cannot grep on word boundaries of
# first and last word
COMPREPLY=" ${COMPREPLY[@]} "
# remove word from list of completions
COMPREPLY=( ${COMPREPLY/ ${i%% *} / } )
done
echo ${COMPREPLY[@]})
) )
# put dashes back
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
COMPREPLY[i]=-${COMPREPLY[i]}
done
return 0
}
complete -F _find -o default find
# Linux ifconfig(8) completion
#
[ $OS = Linux ] &&
_ifconfig()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
case "${COMP_WORDS[1]}" in
-|*[0-9]*)
COMPREPLY=( $( compgen -W '-a up down arp promisc allmulti \
metric mtu dstaddr netmask add del \
tunnel irq io_addr mem_start media \
broadcast pointopoint hw multicast \
address txqueuelen' $cur ))
COMPREPLY=( $( echo " ${COMP_WORDS[@]}" | \
(while read -d ' ' i; do
[ "$i" == "" ] && continue
# flatten array with spaces on either side,
# otherwise we cannot grep on word
# boundaries of first and last word
COMPREPLY=" ${COMPREPLY[@]} "
# remove word from list of completions
COMPREPLY=( ${COMPREPLY/ $i / } )
done
echo ${COMPREPLY[@]})
) )
return 0
;;
esac
COMPREPLY=( $( ifconfig -a | sed -ne 's/^\('$cur'[^ ]*\).*$/\1/p' ))
}
[ $OS = Linux ] && complete -F _ifconfig ifconfig
# RedHat & Debian Linux if{up,down} completion
#
[ $OS = Linux ] && ( have ifup || have ifdown ) &&
_ifupdown()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
if [ $COMP_CWORD = 1 ]; then
if [ -f /etc/debian_version ]; then
# Debian system
COMPREPLY=( $( sed -ne 's/^iface \([^ ]\+\).*$/\1/p' /etc/network/interfaces ) )
else
# Assume Red Hat
COMPREPLY=( $( \ls /etc/sysconfig/network-scripts/ifcfg-* | sed -ne 's/.*ifcfg-\('$cur'.*\)/\1/p' ) )
fi
fi
return 0
}
[ $OS = Linux ] && have ifup && complete -F _ifupdown ifup ifdown
# Linux ipsec(8) completion (for FreeS/WAN). Basic.
#
[ $OS = Linux ] && have ipsec &&
_ipsec()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
if [ $COMP_CWORD = 1 ]; then
COMPREPLY=( $( compgen -W 'auto barf eroute klipsdebug look manual \
pluto ranbits rsasigkey setup showdefaults \
showhostkey spi spigrp tncfg whack' $cur ))
return 0
fi
case ${COMP_WORDS[1]} in
auto)
COMPREPLY=( $( compgen -W '--asynchronous --up --add --delete \
--replace --down --route --unroute \
--ready --status --rereadsecrets' $cur ) )
return 0
;;
manual)
COMPREPLY=( $( compgen -W '--up --down --route --unroute \
--union' $cur ) )
return 0
;;
ranbits)
COMPREPLY=( $( compgen -W '--quick --continuous --bytes' $cur ) )
return 0
;;
setup)
COMPREPLY=( $( compgen -W '--start --stop --restart' $cur ) )
return 0
;;
*)
return 0
;;
esac
return 0
}
[ $OS = Linux ] && [ "$have" ] && complete -F _ipsec ipsec
# cvs(1) completion
#
_cvs()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ $COMP_CWORD = 1 ] || [[ "$prev" == -* ]]; then
COMPREPLY=( $( compgen -W 'add admin checkout commit diff \
export history import log rdiff release remove rtag status \
tag update' $cur ))
fi
return 0
}
complete -F _cvs -o default cvs
# rpm(8) completion. This is quite comprehensive now and covers rpm 4.x
#
have rpm &&
_rpm()
{
dashify()
{
local i
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
if [ ${#COMPREPLY[i]} -le 2 ]; then
COMPREPLY[i]=-${COMPREPLY[i]}
else
COMPREPLY[i]=--${COMPREPLY[i]}
fi
done
}
add_package_list()
{
if [ -r /var/log/rpmpkgs ]; then
# using RHL 7.2 - this is quicker than querying the DB
COMPREPLY=( ${COMPREPLY[@]}
$( sed -ne 's/^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.]\+.*\.rpm$/\1/p' /var/log/rpmpkgs ) )
else
COMPREPLY=( ${COMPREPLY[@]} $( rpm -qa | \
sed -ne 's/^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.]\+$/\1/p' ) )
fi
}
file_glob()
{
local suffix
_expand || return 0
# get extension of current word, if relevant
suffix=${cur##*.}
# nullify it if it's not a substring of the extension we're
# completing on
[ "$suffix" != "${1:0:${#suffix}}" ] && suffix=""
COMPREPLY=( ${COMPREPLY[@]} $( compgen -G $cur\*${1:${#suffix}} ) )
# directory completion if all else fails and current word
# contains a slash
if [ ${#COMPREPLY[@]} = 0 ] && [[ $cur == */* ]]; then
COMPREPLY=( $( compgen -d $cur ) )
fi
}
local cur cur_nodash prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
cur_nodash=${cur#-}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ $COMP_CWORD = 1 ]; then
# first parameter on line
case "$cur" in
-b*)
COMPREPLY=( $( compgen -W 'ba bb bc bi bl bp bs' \
$cur_nodash ) )
dashify
return 0
;;
-t*)
COMPREPLY=( $( compgen -W 'ta tb tc ti tl tp ts' \
$cur_nodash ) )
dashify
return 0
;;
--*)
COMPREPLY=( $( compgen -W 'help version initdb \
checksig recompile rebuild resign addsign rebuilddb \
showrc setperms setugids tarbuild eval install \
upgrade query freshen erase verify querytags rmsource \
rmspec clean' ${cur_nodash#-} ) )
dashify
return 0
;;
*)
COMPREPLY=( $( compgen -W 'b e F i q t U V' \
$cur_nodash ) )
dashify
return 0
;;
esac
fi
case "$prev" in
--@(db|exclude)path|prefix|relocate|root)
COMPREPLY=( $( compgen -d $cur ) )
return 0
;;
--eval)
# get a list of macros
COMPREPLY=( $( sed -ne 's/^\(%'${cur#\%}'[^ '$'\t'']*\).*$/\1/p' \
/usr/lib/rpm/macros ) )
return 0
;;
--pipe)
COMPREPLY=( $( compgen -c $cur ) )
return 0
;;
--rcfile)
COMPREPLY=( $( compgen -f $cur ) )
return 0
;;
--specfile)
# complete on .spec files
file_glob spec
return 0
;;
--whatprovides)
# complete on capabilities
COMPREPLY=( $( rpm -qa --queryformat '%{providename}\n' | grep ^$cur ) )
return 0
;;
--whatrequires)
# complete on capabilities
COMPREPLY=( $( rpm -qa --queryformat '%{requirename}\n' | grep ^$cur ) )
return 0
;;
esac
case "${COMP_WORDS[1]}" in
-@([iFU]*|-install|-freshen|-upgrade))
# complete on list of relevant options
COMPREPLY=( $( compgen -W 'percent force test replacepkgs \
replacefiles root excludedocs includedocs noscripts rcfile \
ignorearch dbpath prefix ignoreos nodeps allfiles ftpproxy \
ftpport justdb httpproxy httpport noorder relocate badreloc \
notriggers excludepath ignoresize oldpackage define eval \
pipe queryformat repackage' ${cur_nodash#-} ))
dashify
# return if $cur is an option
[[ "$cur" == -* ]] && return 0
# add a list of RPMS to possible completions
file_glob rpm
return 0
;;
-q*p*)
# complete on list of relevant options
COMPREPLY=( $( compgen -W 'scripts root rcfile whatprovides \
whatrequires requires triggeredby ftpport ftpproxy httpproxy \
httpport provides triggers dump changelog dbpath filesbypkg \
define eval pipe showrc info list state docfiles \
configfiles queryformat conflicts obsoletes' ${cur_nodash#-} ) )
dashify
# return if $cur is an option
[[ "$cur" == -* ]] && return 0
# add a list of RPMS to possible completions
file_glob rpm
return 0
;;
-*f)
# standard filename completion
COMPREPLY=( $( compgen -f $cur ) )
return 0
;;
-@(e|-erase))
# complete on list of relevant options
COMPREPLY=( $( compgen -W 'allmatches noscripts notriggers \
nodeps test repackage' ${cur_nodash#-} ) )
dashify
# return if $cur is an option
[[ "$cur" == -* ]] && return 0
add_package_list
return 0
;;
-q*)
# complete on list of relevant options
COMPREPLY=( $( compgen -W 'scripts root rcfile whatprovides \
whatrequires requires triggeredby ftpport ftpproxy httpproxy \
httpport provides triggers dump changelog dbpath specfile \
querybynumber last filesbypkg define eval pipe showrc info \
list state docfiles configfiles queryformat conflicts \
obsoletes' ${cur_nodash#-} ) )
dashify
# return if $cur is an option
[[ "$cur" == -* ]] && return 0
# don't complete on packages if we are querying all packages
[[ ${COMP_WORDS[1]} == -qa* ]] && return 0
add_package_list
return 0
;;
-@(K|-checksig))
# complete on list of relevant options
COMPREPLY=( $( compgen -W 'nopgp nogpg nomd5' \
${cur_nodash#-} ) )
dashify
# return if $cur is an option
[[ "$cur" == -* ]] && return 0
# add a list of RPMS to possible completions
file_glob rpm
return 0
;;
-@([Vy]*|-verify))
# complete on list of relevant options
COMPREPLY=( $( compgen -W 'root rcfile dbpath nodeps nofiles \
noscripts nomd5' ${cur_nodash#-} ) )
dashify
# return if $cur is an option
[[ "$cur" == -* ]] && return 0
add_package_list
return 0
;;
-[bt]*)
# complete on list of relevant options
COMPREPLY=( $( compgen -W 'short-circuit timecheck clean \
rmsource rmspec test sign buildroot target buildarch buildos \
nobuild' ${cur_nodash#-} ) )
dashify
# return if $cur is an option
[[ "$cur" == -* ]] && return 0
if [[ ${COMP_WORDS[1]} == -b* ]]; then
# complete on .spec files
file_glob spec
else
_expand || return 0
# complete on .tar files
COMPREPLY=( $( compgen -G $cur\*.+(tgz|tar.+(gz|bz2)) ) )
fi
return 0
;;
--re@(build|compile))
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W 'nodeps' ${cur_nodash#-} ) )
dashify
return 0
fi
_expand || return 0
# complete on source RPMs
COMPREPLY=( $( compgen -G $cur\*.src.rpm ) )
return 0
;;
--tarbuild)
_expand || return 0
# complete on tarred sources
COMPREPLY=( $( compgen -G $cur\*.+(tgz|tar.+(gz|bz2)) ) )
return 0
;;
--@(re|add)sign)
# complete on RPMs
file_glob rpm
return 0
;;
--set@(perms|gids))
add_package_list
return 0
;;
--@(clean|rms@(ource|pec)))
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W 'clean rmsource rmspec' \
${cur_nodash#-} ) )
dashify
return 0
fi
file_glob spec
return 0
;;
-*g)
# package group completion
local IFS=$'\t'
# remove trailing backslash, or grep will complain
cur=${cur%'\'}
COMPREPLY=( $( rpm -qa --queryformat '%{group}\n' | \
grep ^$cur ) )
# backslash escape spaces and translate newlines to tabs
COMPREPLY=( $( echo ${COMPREPLY[@]} | sed 's/ /\\ /g' | \
tr '\n' '\t' ) )
return 0
;;
esac
return 0
}
[ "$have" ] && complete -F _rpm -o filenames rpm
# Debian Linux apt-get(8) completion.
#
have apt-get &&
_apt-get()
{
local cur prev special i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
for (( i=0; i < ${#COMP_WORDS}-1; i++ )); do
if [[ ${COMP_WORDS[i]} == @(install|remove|source) ]]; then
special=${COMP_WORDS[i]}
fi
done
if [ -n "$special" ]; then
case $special in
@(install|remove|source))
COMPREPLY=( $( apt-cache pkgnames $cur ) )
return 0
;;
esac
fi
if [[ "$prev" == -*c ]] || [ "$prev" = --config-file ]; then
COMPREPLY=( $( compgen -f $cur ) )
else
COMPREPLY=( $( compgen -W 'update upgrade dselect-upgrade \
dist-upgrade install remove source check \
clean autoclean -d -f -h -v -m -q -s -y -u \
-b -c -o --download-only --fix-broken --help \
--version --ignore-missing --fix-missing \
--no-download --quiet --simulate \
--just-print --dry-run --recon --no-act \
--yes --assume-yes --show-upgraded \
--compile --build --ignore-hold \
--no-upgrade --force-yes --print-uris \
--purge --reinstall --list-cleanup \
--trivial-only --no-remove --diff-only \
--tar-only --config-file --option ' | \
grep ^$cur ) )
fi
return 0
}
[ "$have" ] && complete -F _apt-get -o filenames apt-get
# Debian Linux apt-cache(8) completion.
#
have apt-cache &&
_apt-cache()
{
local cur prev special i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
for (( i=0; i < ${#COMP_WORDS}-1; i++ )); do
if [[ ${COMP_WORDS[i]} == @(add|showpkg) ]]; then
special=${COMP_WORDS[i]}
fi
done
if [ -n "$special" ]; then
case $special in
add)
COMPREPLY=( $( compgen -f $cur ) )
return 0
;;
showpkg)
COMPREPLY=( $( apt-cache pkgnames $cur ) )
return 0
;;
esac
fi
if [[ "$prev" == -*c ]] || [ "$prev" = --config-file ]; then
COMPREPLY=( $( compgen -f $cur ) )
else
COMPREPLY=( $( compgen -W 'add gencaches showpkg stats dump \
dumpavail unmet check search show showpkg \
depends pkgnames -h -v -p -s -q -i -f -a -g -c \
-o --help --version --pkg-cache --src-cache \
--quiet --important --full --all-versions \
--no-generate --names-only --all-names \
--config-file --option' | grep ^$cur ) )
fi
return 0
}
[ "$have" ] && complete -F _apt-cache -o filenames apt-cache
# chsh(1) completion
#
_chsh()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ "$prev" = "-s" ]; then
COMPREPLY=( $( chsh -l | grep ^$cur ) )
else
COMPREPLY=( $( compgen -u $cur ) )
fi
return 0
}