-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_completion
9299 lines (8315 loc) · 211 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 - programmable completion functions for bash 3.x
# (backwards compatible with bash 2.05b)
#
# $Id: bash_completion,v 1.872 2006/03/01 16:20:18 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.
#
# The latest version of this software can be obtained here:
#
# http://www.caliban.org/bash/index.shtml#completion
#
# RELEASE: 20060301
[ -n "${BASH_COMPLETION_DEBUG:-}" ] && set -v || set +v
# Alter the following to reflect the location of this file.
#
{
# These declarations must go within braces in order to be able to silence
# readonly variable errors.
[ -n "$BASH_COMPLETION" ] || BASH_COMPLETION="${BASH_COMPLETION:-$HOME/bash_completion}"
[ -n "$BASH_COMPLETION_DIR" ] || BASH_COMPLETION_DIR="${BASH_COMPLETION_DIR:=/etc/bash_completion.d}"
} 2>/dev/null || :
readonly BASH_COMPLETION BASH_COMPLETION_DIR
# Set a couple of useful vars
#
UNAME=$( uname -s )
# strip OS type and version under Cygwin (e.g. CYGWIN_NT-5.1 => Cygwin)
UNAME=${UNAME/CYGWIN_*/Cygwin}
RELEASE=$( uname -r )
# features supported by bash 2.05 and higher
if [ ${BASH_VERSINFO[0]} -eq 2 ] && [[ ${BASH_VERSINFO[1]} > 04 ]] ||
[ ${BASH_VERSINFO[0]} -gt 2 ]; then
declare -r bash205=$BASH_VERSION 2>/dev/null || :
default="-o default"
dirnames="-o dirnames"
filenames="-o filenames"
fi
# features supported by bash 2.05b and higher
if [ ${BASH_VERSINFO[0]} -eq 2 ] && [[ ${BASH_VERSINFO[1]} = "05b" ]] ||
[ ${BASH_VERSINFO[0]} -gt 2 ]; then
declare -r bash205b=$BASH_VERSION 2>/dev/null || :
nospace="-o nospace"
fi
# features supported by bash 3.0 and higher
if [ ${BASH_VERSINFO[0]} -gt 2 ]; then
declare -r bash3=$BASH_VERSION 2>/dev/null || :
bashdefault="-o bashdefault"
plusdirs="-o plusdirs"
fi
# 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 pushd
# The following section lists completions that are redefined later
# Do NOT break these over multiple lines.
#
# START exclude -- do NOT remove this line
complete -f -X '!*.?(t)bz?(2)' bunzip2 bzcat bzcmp bzdiff bzegrep bzfgrep bzgrep
complete -f -X '!*.@(zip|ZIP|jar|JAR|exe|EXE|pk3|war|wsz|ear|zargo|xpi|sxw|ott)' unzip zipinfo
complete -f -X '*.Z' compress znew
complete -f -X '!*.@(Z|gz|tgz|Gz|dz)' gunzip zcmp zdiff zcat zegrep zfgrep zgrep zless zmore
complete -f -X '!*.Z' uncompress
complete -f -X '!*.@(gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX)' ee display
complete -f -X '!*.@(gif|jp?(e)g|tif?(f)|png|p[bgp]m|bmp|x[bp]m|rle|rgb|pcx|fits|pm|GIF|JPG|JP?(E)G|TIF?(F)|PNG|P[BGP]M|BMP|X[BP]M|RLE|RGB|PCX|FITS|PM)' xv qiv
complete -f -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2|.Z))' gv ggv kghostview
complete -f -X '!*.@(dvi|DVI)?(.@(gz|Z|bz2))' xdvi
complete -f -X '!*.@(dvi|DVI)' dvips dviselect dvitype kdvi dvipdf advi
complete -f -X '!*.@(pdf|PDF)' acroread gpdf xpdf kpdf
complete -f -X '!*.@(@(?(e)ps|?(E)PS)?(.gz|.GZ)|pdf|PDF|gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX)' evince
complete -f -X '!*.@(?(e)ps|?(E)PS)' ps2pdf
complete -f -X '!*.texi*' makeinfo texi2html
complete -f -X '!*.@(?(la)tex|?(LA)TEX|texi|TEXI|dtx|DTX|ins|INS)' tex latex slitex jadetex pdfjadetex pdftex pdflatex texi2dvi
complete -f -X '!*.@(mp3|MP3)' mpg123 mpg321 madplay
complete -f -X '!*.@(mp?(e)g|MP?(E)G|wma|avi|AVI|asf|vob|VOB|bin|dat|vcd|ps|pes|fli|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp3|MP3|ogg|OGG|ogm|OGM|mp4|MP4|wav|WAV|asx|ASX|mng|MNG)' xine aaxine fbxine kaffeine
complete -f -X '!*.@(avi|asf|wmv)' aviplay
complete -f -X '!*.@(rm?(j)|ra?(m)|smi?(l))' realplay
complete -f -X '!*.@(mpg|mpeg|avi|mov|qt)' xanim
complete -f -X '!*.@(ogg|OGG|m3u|flac|spx)' ogg123
complete -f -X '!*.@(mp3|MP3|ogg|OGG|pls|m3u)' gqmpeg freeamp
complete -f -X '!*.fig' xfig
complete -f -X '!*.@(mid?(i)|MID?(I))' playmidi
complete -f -X '!*.@(mid?(i)|MID?(I)|rmi|RMI|rcp|RCP|[gr]36|[GR]36|g18|G18|mod|MOD|xm|XM|it|IT|x3m|X3M)' timidity
complete -f -X '*.@(o|so|so.!(conf)|a|t@(ar?(.@(Z|gz|bz?(2)))|gz|bz?(2))|rpm|zip|ZIP|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MPG|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)' vi vim gvim rvim view rview rgvim rgview gview
complete -f -X '*.@(o|so|so.!(conf)|a|rpm|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MPG|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)' emacs
complete -f -X '!*.@(exe|EXE|com|COM|scr|SCR|exe.so)' wine
complete -f -X '!*.@(zip|ZIP|z|Z|gz|GZ|tgz|TGZ)' bzme
complete -f -X '!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))' netscape mozilla lynx opera galeon curl dillo elinks amaya
complete -f -X '!*.@(sxw|stw|sxg|sgl|doc|dot|rtf|txt|htm|html|odt|ott|odm)' oowriter
complete -f -X '!*.@(sxi|sti|pps|ppt|pot|odp|otp)' ooimpress
complete -f -X '!*.@(sxc|stc|xls|xlw|xlt|csv|ods|ots)' oocalc
complete -f -X '!*.@(sxd|std|sda|sdd|odg|otg)' oodraw
complete -f -X '!*.@(sxm|smf|mml|odf)' oomath
complete -f -X '!*.odb' oobase
complete -f -X '!*.rpm' rpm2cpio
# FINISH exclude -- do not remove this line
# start of section containing compspecs that can be handled within bash
# user commands see only users
complete -u su usermod userdel passwd chage write chfn groups slay w
# group commands see only groups
[ -n "$bash205" ] && complete -g groupmod groupdel newgrp 2>/dev/null
# bg completes with stopped jobs
complete -A stopped -P '%' bg
# other job commands
complete -j -P '%' fg jobs disown
# readonly and unset complete with shell variables
complete -v 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
# type and which complete on commands
complete -c command type which
# builtin completes on builtins
complete -b builtin
# start of section containing completion functions called by other functions
# This function checks whether we have a given program on the system.
# No need for bulky functions in memory if we don't.
#
have()
{
unset -v have
PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type $1 &>/dev/null &&
have="yes"
}
# use GNU sed if we have it, since its extensions are still used in our code
#
[ $UNAME != Linux ] && have gsed && alias sed=gsed
# This function checks whether a given readline variable
# is `on'.
#
_rl_enabled()
{
[[ "$( bind -v )" = *$1+([[:space:]])on* ]]
}
# This function performs file and directory completion. It's better than
# simply using 'compgen -f', because it honours spaces in filenames.
# If passed -d, it completes only on directories. If passed anything else,
# it's assumed to be a file glob to complete on.
#
_filedir()
{
local IFS=$'\t\n' xspec #glob
_expand || return 0
#glob=$(set +o|grep noglob) # save glob setting.
#set -f # disable pathname expansion (globbing)
if [ "${1:-}" = -d ]; then
COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -d -- $cur ) )
#eval "$glob" # restore glob setting.
return 0
fi
xspec=${1:+"!*.$1"} # set only if glob passed in as $1
COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$cur" ) )
#eval "$glob" # restore glob setting.
}
# This function completes on signal names
#
_signals()
{
local i
# 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
}
# This function completes on configured network interfaces
#
_configured_interfaces()
{
if [ -f /etc/debian_version ]; then
# Debian system
COMPREPLY=( $( sed -ne 's|^iface \([^ ]\+\).*$|\1|p' \
/etc/network/interfaces ) )
elif [ -f /etc/SuSE-release ]; then
# SuSE system
COMPREPLY=( $( command ls \
/etc/sysconfig/network/ifcfg-* | \
sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) )
elif [ -f /etc/pld-release ]; then
# PLD Linux
COMPREPLY=( $( command ls -B \
/etc/sysconfig/interfaces | \
sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) )
else
# Assume Red Hat
COMPREPLY=( $( command ls \
/etc/sysconfig/network-scripts/ifcfg-* | \
sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) )
fi
}
# This function completes on all available network interfaces
# -a: restrict to active interfaces only
# -w: restrict to wireless interfaces only
#
_available_interfaces()
{
local cmd
if [ "${1:-}" = -w ]; then
cmd="iwconfig"
elif [ "${1:-}" = -a ]; then
cmd="ifconfig"
else
cmd="ifconfig -a"
fi
COMPREPLY=( $( eval $cmd 2>/dev/null | \
sed -ne 's|^\('$cur'[^[:space:][:punct:]]\{1,\}\).*$|\1|p') )
}
# This function expands tildes in pathnames
#
_expand()
{
[ "$cur" != "${cur%\\}" ] && cur="$cur\\"
# expand ~username type directory specifications
if [[ "$cur" == \~*/* ]]; then
eval cur=$cur
elif [[ "$cur" == \~* ]]; then
cur=${cur#\~}
COMPREPLY=( $( compgen -P '~' -u $cur ) )
return ${#COMPREPLY[@]}
fi
}
# This function completes on process IDs.
# AIX and Solaris ps prefers X/Open syntax.
[ $UNAME = SunOS -o $UNAME = AIX ] &&
_pids()
{
COMPREPLY=( $( compgen -W '$( command ps -efo pid | sed 1d )' -- $cur ))
} ||
_pids()
{
COMPREPLY=( $( compgen -W '$( command ps axo pid | sed 1d )' -- $cur ) )
}
# This function completes on process group IDs.
# AIX and SunOS prefer X/Open, all else should be BSD.
[ $UNAME = SunOS -o $UNAME = AIX ] &&
_pgids()
{
COMPREPLY=( $( compgen -W '$( command ps -efo pgid | sed 1d )' -- $cur ))
} ||
_pgids()
{
COMPREPLY=( $( compgen -W '$( command ps axo pgid | sed 1d )' -- $cur ))
}
# This function completes on user IDs
#
_uids()
{
if type getent &>/dev/null; then
COMPREPLY=( $( getent passwd | \
awk -F: '{if ($3 ~ /^'$cur'/) print $3}' ) )
elif type perl &>/dev/null; then
COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($uid) = (getpwent)[2]) { print $uid . "\n" }'"'"' )' -- $cur ) )
else
# make do with /etc/passwd
COMPREPLY=( $( awk 'BEGIN {FS=":"} {if ($3 ~ /^'$cur'/) print $3}'\
/etc/passwd ) )
fi
}
# This function completes on group IDs
#
_gids()
{
if type getent &>/dev/null; then
COMPREPLY=( $( getent group | \
awk -F: '{if ($3 ~ /^'$cur'/) print $3}' ) )
elif type perl &>/dev/null; then
COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($gid) = (getgrent)[2]) { print $gid . "\n" }'"'"' )' -- $cur ) )
else
# make do with /etc/group
COMPREPLY=( $( awk 'BEGIN {FS=":"} {if ($3 ~ /^'$cur'/) print $3}'\
/etc/group ) )
fi
}
# This function completes on services
#
_services()
{
local sysvdir famdir
[ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d
famdir=/etc/xinetd.d
COMPREPLY=( $( builtin echo $sysvdir/!(*.rpmsave|*.rpmorig|*~|functions)) )
if [ -d $famdir ]; then
COMPREPLY=( ${COMPREPLY[@]} $( builtin echo $famdir/!(*.rpmsave|*.rpmorig|*~)) )
fi
COMPREPLY=( $( compgen -W '${COMPREPLY[@]#@($sysvdir|$famdir)/}' -- $cur ) )
}
# This function complete on modules
#
_modules()
{
local modpath
modpath=/lib/modules/$1
COMPREPLY=( $( command ls -R $modpath | \
sed -ne 's/^\('$cur'.*\)\.k\?o\(\|.gz\)$/\1/p') )
}
# this function complete on user:group format
#
_usergroup()
{
local IFS=$'\n'
cur=${cur//\\\\ / }
if [[ $cur = *@(\\:|.)* ]] && [ -n "$bash205" ]; then
user=${cur%%*([^:.])}
COMPREPLY=( $(compgen -P ${user/\\\\} -g -- ${cur##*[.:]}) )
elif [[ $cur = *:* ]] && [ -n "$bash205" ]; then
COMPREPLY=( $( compgen -g -- ${cur##*[.:]} ) )
else
COMPREPLY=( $( compgen -S : -u -- $cur ) )
fi
}
# this function count the number of mandatory args
#
_count_args()
{
args=1
for (( i=1; i < COMP_CWORD; i++ )); do
if [[ "${COMP_WORDS[i]}" != -* ]]; then
args=$(($args+1))
fi
done
}
# start of section containing completion functions for bash built-ins
# bash alias completion
#
_alias()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[$COMP_CWORD]}
case "$COMP_LINE" in
*[^=])
COMPREPLY=( $( compgen -A alias -S '=' -- $cur ) )
;;
*=)
COMPREPLY=( "$( alias ${cur%=} 2>/dev/null | \
sed -e 's|^alias '$cur'\(.*\)$|\1|' )" )
;;
esac
}
complete -F _alias $nospace alias
# bash export completion
#
_export()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[$COMP_CWORD]}
case "$COMP_LINE" in
*=\$*)
COMPREPLY=( $( compgen -v -P '$' -- ${cur#*=\$} ) )
;;
*[^=])
COMPREPLY=( $( compgen -v -S '=' -- $cur ) )
;;
*=)
COMPREPLY=( "$( eval echo -n \"$`echo ${cur%=}`\" |
( echo -n \'
sed -e 's/'\''/'\''\\\'\'''\''/g'
echo -n \' ) )" )
;;
esac
}
complete -F _export $default $nospace export
# bash shell function completion
#
_function()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [[ $1 == @(declare|typeset) ]]; then
if [ "$prev" = -f ]; then
COMPREPLY=( $( compgen -A function -- $cur ) )
elif [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-a -f -F -i -r -x -p' -- \
$cur ) )
fi
elif [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $( compgen -A function -- $cur ) )
else
COMPREPLY=( "() $( type -- ${COMP_WORDS[1]} | sed -e 1,2d )" )
fi
}
complete -F _function function declare typeset
# bash complete completion
#
_complete()
{
local cur prev options
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
case $prev in
-o)
options="default dirnames filenames"
[ -n "$bash205b" ] && options="$options nospace"
[ -n "$bash3" ] && options="$options bashdefault plusdirs"
COMPREPLY=( $( compgen -W "$options" -- $cur ) )
return 0
;;
-A)
COMPREPLY=( $( compgen -W 'alias arrayvar binding \
builtin command directory disabled enabled \
export file function group helptopic hostname \
job keyword running service setopt shopt \
signal stopped user variable' -- $cur ) )
return 0
;;
-C)
COMPREPLY=( $( compgen -A command -- $cur ) )
return 0
;;
-F)
COMPREPLY=( $( compgen -A function -- $cur ) )
return 0
;;
-@(p|r))
COMPREPLY=( $( complete -p | sed -e 's|.* ||' | \
grep "^$cur" ) )
return 0
;;
esac
if [[ "$cur" == -* ]]; then
# relevant options completion
options="-a -b -c -d -e -f -g -j -k -s -v -u -A -G -W -P -S -X -F -C"
[ -n "$bash205" ] && options="$options -o"
COMPREPLY=( $( compgen -W "$options" -- $cur ) )
else
COMPREPLY=( $( compgen -A command -- $cur ) )
fi
}
complete -F _complete complete
# start of section containing completion functions for external programs
# a little help for FreeBSD ports users
[ $UNAME = FreeBSD ] && complete -W 'index search fetch fetch-list \
extract patch configure build install reinstall \
deinstall clean clean-depends kernel buildworld' make
# This completes on a list of all available service scripts for the
# 'service' command and/or the SysV init.d directory, followed by
# that script's available commands
#
{ have service || [ -d /etc/init.d/ ]; } &&
_service()
{
local cur sysvdir
COMPREPLY=()
prev=${COMP_WORDS[COMP_CWORD-1]}
cur=${COMP_WORDS[COMP_CWORD]}
# don't complete for things like killall, ssh and mysql if it's
# the standalone command, rather than the init script
[[ ${COMP_WORDS[0]} != @(*init.d/!(functions|~)|service) ]] && return 0
# don't complete past 2nd token
[ $COMP_CWORD -gt 2 ] && return 0
[ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
|| sysvdir=/etc/init.d
if [[ $COMP_CWORD -eq 1 ]] && [[ $prev == "service" ]]; then
_services
else
COMPREPLY=( $( compgen -W '`sed -ne "y/|/ /; \
s/^.*Usage.*{\(.*\)}.*$/\1/p" \
$sysvdir/${prev##*/} 2>/dev/null`' -- $cur ) )
fi
return 0
} &&
complete -F _service service
[ -d /etc/init.d/ ] && complete -F _service $default \
$(for i in /etc/init.d/*; do echo ${i##*/}; done)
# chown(1) completion
#
_chown()
{
local cur
cur=${COMP_WORDS[COMP_CWORD]}
# options completion
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes \
--dereference --no-dereference --from= --silent --quiet \
--reference= --recursive --verbose --help --version' -- $cur ) )
else
_count_args
case $args in
1)
_usergroup
;;
*)
_filedir
;;
esac
fi
}
complete -F _chown $filenames chown
# chgrp(1) completion
#
_chgrp()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
cur=${cur//\\\\/}
prev=${COMP_WORDS[COMP_CWORD-1]}
# options completion
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes \
--dereference --no-dereference --silent --quiet \
--reference= --recursive --verbose --help --version' -- $cur ) )
return 0
fi
# first parameter on line or first since an option?
if [ $COMP_CWORD -eq 1 ] && [[ "$cur" != -* ]] || \
[[ "$prev" == -* ]] && [ -n "$bash205" ]; then
local IFS=$'\n'
COMPREPLY=( $( compgen -g $cur 2>/dev/null ) )
else
_filedir || return 0
fi
return 0
}
complete -F _chgrp $filenames 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]}
COMPREPLY=( $( compgen -W '$( mount | cut -d" " -f 3 )' -- $cur ) )
return 0
}
complete -F _umount $dirnames umount
# mount(8) completion. This will pull a list of possible mounts out of
# /etc/{,v}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 host
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
[[ "$cur" == \\ ]] && cur="/"
for i in {,/usr}/{,s}bin/showmount; do [ -x $i ] && sm=$i && break; done
if [ -n "$sm" ] && [[ "$cur" == *:* ]]; then
COMPREPLY=( $( $sm -e ${cur%%:*} | sed 1d | \
grep ^${cur#*:} | awk '{print $1}' ) )
elif [[ "$cur" == //* ]]; then
host=${cur#//}
host=${host%%/*}
if [ -n "$host" ]; then
COMPREPLY=( $( compgen -W "$( echo $( smbclient -d 0 -NL $host 2>/dev/null|
sed -ne '/^['"$'\t '"']*Sharename/,/^$/p' |
sed -ne '3,$s|^[^A-Za-z]*\([^'"$'\t '"']*\).*$|//'$host'/\1|p' ) )" -- "$cur" ) )
fi
elif [ -r /etc/vfstab ]; then
# Solaris
COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' \
/etc/vfstab | grep "^$cur" ) )
elif [ ! -e /etc/fstab ]; then
# probably Cygwin
COMPREPLY=( $( mount | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' \
| grep "^$cur" ) )
else
# probably Linux
COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' \
/etc/fstab | grep "^$cur" ) )
fi
return 0
}
complete -F _mount $default $filenames mount
# Linux rmmod(8) completion. This completes on a list of all currently
# installed kernel modules.
#
have rmmod && {
_rmmod()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $( /sbin/lsmod | \
awk '{if (NR != 1 && $1 ~ /^'$cur'/) print $1}' 2>/dev/null ))
return 0
}
complete -F _rmmod rmmod
# Linux insmod(8), modprobe(8) and modinfo(8) completion. This completes on a
# list of all available modules for the version of the kernel currently
# running.
#
_insmod()
{
local cur prev modpath
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
# behave like lsmod for modprobe -r
if [ $1 = "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
_filedir '@(?(k)o?(.gz))'
return 0
fi
if [ $COMP_CWORD -gt 1 ] &&
[[ "${COMP_WORDS[COMP_CWORD-1]}" != -* ]]; then
# do module parameter completion
COMPREPLY=( $( /sbin/modinfo -p ${COMP_WORDS[1]} 2>/dev/null | \
awk '{if ($1 ~ /^parm:/ && $2 ~ /^'$cur'/) { print $2 } \
else if ($1 !~ /:/ && $1 ~ /^'$cur'/) { print $1 }}' ) )
else
_modules $(uname -r)
fi
return 0
}
complete -F _insmod $filenames insmod modprobe modinfo
}
# man(1) completion
#
[ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \
-o $UNAME = FreeBSD -o $UNAME = SunOS -o $UNAME = Cygwin \
-o $UNAME = OpenBSD ] &&
_man()
{
local cur prev sect manpath UNAME
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
_expand || return 0
# default completion if parameter contains /
if [[ "$cur" == */* ]]; then
_filedir
return 0
fi
UNAME=$( uname -s )
# strip OS type and version under Cygwin
UNAME=${UNAME/CYGWIN_*/Cygwin}
if [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = FreeBSD \
-o $UNAME = Cygwin ]; then
manpath=$( manpath 2>/dev/null || command man --path )
else
manpath=$MANPATH
fi
if [ -z "$manpath" ]; then
COMPREPLY=( $( compgen -c -- $cur ) )
return 0
fi
# determine manual section to search
[[ "$prev" == [0-9ln] ]] && sect=$prev || sect='*'
manpath=$manpath:
if [ -n "$cur" ]; then
manpath="${manpath//://*man$sect/$cur* } ${manpath//://*cat$sect/$cur* }"
else
manpath="${manpath//://*man$sect/ } ${manpath//://*cat$sect/ }"
fi
# redirect stderr for when path doesn't exist
COMPREPLY=( $( eval command ls "$manpath" 2>/dev/null ) )
# weed out directory path names and paths to man pages
COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
# strip suffix from man pages
COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} )
COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) )
[[ "$prev" != [0-9ln] ]] && _filedir '[0-9ln]'
return 0
}
[ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \
-o $UNAME = FreeBSD -o $UNAME = SunOS -o $UNAME = Cygwin \
-o $UNAME = OpenBSD ] && \
complete -F _man $filenames man
# renice(8) completion
#
_renice()
{
local command cur curopt i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
command=$1
i=0
# walk back through command line and find last option
while [ $i -le $COMP_CWORD -a ${#COMPREPLY[@]} -eq 0 ]; do
curopt=${COMP_WORDS[COMP_CWORD-$i]}
case "$curopt" in
-u)
COMPREPLY=( $( compgen -u -- $cur ) )
;;
-g)
_pgids
;;
-p|$command)
_pids
;;
esac
i=$(( ++i ))
done
}
complete -F _renice renice
# kill(1) completion
#
_kill()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then
# return list of available signals
_signals
else
# return list of available PIDs
_pids
fi
}
complete -F _kill kill
# Linux and FreeBSD killall(1) completion.
#
[ $UNAME = Linux -o $UNAME = FreeBSD ] &&
_killall()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then
_signals
else
COMPREPLY=( $( compgen -W '$( command ps axo command | \
sed -ne "1d; s/^\[\?\([^-][^] ]*\).*$/\1/p" | \
sed -e "s/.*\///" )' -- $cur ) )
fi
return 0
}
[ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _killall killall pkill
# Linux and FreeBSD pgrep(1) completion.
#
[ $UNAME = Linux -o $UNAME = FreeBSD ] &&
_pgrep()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $( compgen -W '$( command ps axo command | \
sed -ne "1d; s/^\[\?\([^-][^] ]*\).*$/\1/p" | \
sed -e "s/.*\///" )' -- $cur ) )
return 0
}
[ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _pgrep pgrep
# Linux pidof(8) completion.
[ $UNAME = Linux ] && complete -F _pgrep pidof
# 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 prev i exprfound onlyonce
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
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' -- $cur ) )
return 0
;;
-?(a|c)newer|-fls|-fprint?(0|f)|-?(i)?(l)name)
_filedir
return 0
;;
-fstype)
# this is highly non-portable
[ -e /proc/filesystems ] &&
COMPREPLY=( $( cut -d$'\t' -f 2 /proc/filesystems | \
grep "^$cur" ) )
return 0
;;
-gid)
_gids
return 0
;;
-group)
if [ -n "$bash205" ]; then
COMPREPLY=( $( compgen -g -- $cur 2>/dev/null) )
fi
return 0
;;
-?(x)type)
COMPREPLY=( $( compgen -W 'b c d p f l s' -- $cur ) )
return 0
;;
-uid)
_uids
return 0
;;
-user)
COMPREPLY=( $( compgen -u -- $cur ) )
return 0
;;
-exec|-ok)
COMP_WORDS=(COMP_WORDS[0] $cur)
COMP_CWORD=1
_command
return 0
;;
-[acm]min|-[acm]time|-?(i)?(l)name|-inum|-?(i)path|-?(i)regex| \
-links|-perm|-size|-used|-printf)
# do nothing, just wait for a parameter to be given
return 0
;;
esac
_expand || return 0
# set exprfound to 1 if there is already an expression present
for i in ${COMP_WORDS[@]}; do
[[ "$i" = [-\(\),\!]* ]] && exprfound=1 && break
done
# handle case where first parameter is not a dash option
if [ "$exprfound" != 1 ] && [[ "$cur" != [-\(\),\!]* ]]; then
_filedir -d
return 0
fi
# complete using basic options
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' -- $cur ) )
# this removes any options from the list of completions that have
# already been specified somewhere on the command line, as long as
# these options can only be used once (in a word, "options", in
# opposition to "tests" and "actions", as in the find(1) manpage).
onlyonce=' -daystart -depth -follow -help -maxdepth -mindepth -mount \
-noleaf -version -xdev '
COMPREPLY=( $( echo "${COMP_WORDS[@]}" | \
(while read -d ' ' i; do
[ "$i" == "" ] ||
[ "${onlyonce/ ${i%% *} / }" == "$onlyonce" ] &&
continue
# flatten array with spaces on either side,
# otherwise we cannot grep on word boundaries of