diff --git a/CHANGES b/CHANGES index e1ba72b8..98d6fb5b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,18 +1,56 @@ bash-completion (2.x) + [ Guillaume Rousse ] + * added pure-perl perldoc completion helper, using work from Aristotle + Pagaltzis (pagaltzis@gmx.de) [ David Paleino ] * Fixed "service" completion, thanks to John Hedges (Debian: #586210) [ Ville Skyttä ] * Activate hping2 completion also for hping and hping3. - * Add crontab and lrzip completions. - * Add gif to mplayer filename completions (Alioth: #312512). + * Add badblocks, compgen, crontab, dumpe2fs, e2freefrag, e2label, ether-wake, + filefrag, iftop, lrzip, POSIX sh, sysbench, tune2fs, xmodmap, and xrdb + completions. + * Add *.gif (Alioth: #312512), *.3gpp, *.3gpp2, and *.awb to mplayer + filename completions. * Add "short" tarball extensions to unxz, unlzma etc completions. - * Improve /etc/init.d/* and sqlite3 completions. + * Improve /etc/init.d/*, ipmitool, jar, mencoder, mplayer, povray, sqlite3, + and general help parsing completions. + * Fix p4 and povray completions (Alioth: #312625). + * Add *.xsd, *.xsl, *.rng, and *.wsdl to xmllint filename completions. + * Recognize rpm query mode based on the --file, --group, --package, and + --all long options (RedHat: #630328). + * Improve rpm query option completions. + * Drop bad kompare filename completion (Alioth: #312708). + * Make _filedir and _filedir_xspec complete uppercase versions of their + filename extension arguments in addition to exact case matches. + * IPv6 known hosts completion fixes (Alioth: #312695, RedHat: #630658). + * Fixes to completions for filenames containing tabs (RedHat: #629518). [ Freddy Vulto ] * Added _tilde(), fix ~username completion (Alioth: #312613, Debian: #587095) * Speed up `compopt' availability detection + * Fix _filedir `-o filenames' detection on bash-3 (Alioth: #312646) + * Fix __reassemble_comp_words_by_ref (Alioth #312740) + + [ Anton Khirnov ] + * Improve mplayer and mencoder completions. + + [ Paul Walmsley ] + * Add *.webm to mplayer file completions (Debian: #588079). + + [ Miklos Vajna ] + * Add *.amr to mplayer file completions (Alioth: #312634). + + [ Andrej Gelenberg ] + * Add *.part (partially downloaded) to mplayer and xine-based player + completions (Alioth: #312657). + + [ Stephen Gildea ] + * Fix false posives for non-option words in _parse_help (Alioth: #312750). + + [ Andrey G. Grozin ] + * Add *.fb2 to okular filename completions. -- David Paleino Wed, 16 Jun 2010 17:53:22 +0200 diff --git a/Makefile.am b/Makefile.am index 331d234c..94016028 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,175 +1,7 @@ -SUBDIRS = test +SUBDIRS = completions helpers test sysconf_DATA = bash_completion -bashcompdir = $(sysconfdir)/bash_completion.d -bashcomp_DATA = contrib/abook \ - contrib/ant \ - contrib/apache2ctl \ - contrib/apt \ - contrib/apt-build \ - contrib/aptitude \ - contrib/aspell \ - contrib/autorpm \ - contrib/bash-builtins \ - contrib/bind-utils \ - contrib/bitkeeper \ - contrib/bittorrent \ - contrib/bluez \ - contrib/brctl \ - contrib/bzip2 \ - contrib/cardctl \ - contrib/cfengine \ - contrib/chkconfig \ - contrib/chsh \ - contrib/cksfv \ - contrib/clisp \ - contrib/configure \ - contrib/coreutils \ - contrib/cowsay \ - contrib/cpan2dist \ - contrib/cpio \ - contrib/crontab \ - contrib/cups \ - contrib/cryptsetup \ - contrib/cvs \ - contrib/cvsps \ - contrib/dd \ - contrib/dhclient \ - contrib/dict \ - contrib/dpkg \ - contrib/dselect \ - contrib/dsniff \ - contrib/findutils \ - contrib/freeciv \ - contrib/fuse \ - contrib/gcc \ - contrib/gcl \ - contrib/gdb \ - contrib/genisoimage \ - contrib/getent \ - contrib/gkrellm \ - contrib/gnatmake \ - contrib/gpg \ - contrib/gpg2 \ - contrib/gzip \ - contrib/heimdal \ - contrib/hping2 \ - contrib/iconv \ - contrib/ifupdown \ - contrib/imagemagick \ - contrib/info \ - contrib/iptables \ - contrib/ipmitool \ - contrib/ipsec \ - contrib/ipv6calc \ - contrib/isql \ - contrib/jar \ - contrib/java \ - contrib/k3b \ - contrib/kldload \ - contrib/larch \ - contrib/ldapvi \ - contrib/lftp \ - contrib/lilo \ - contrib/links \ - contrib/lintian \ - contrib/lisp \ - contrib/lrzip \ - contrib/lvm \ - contrib/lzma \ - contrib/lzop \ - contrib/mailman \ - contrib/make \ - contrib/man \ - contrib/mc \ - contrib/mcrypt \ - contrib/mdadm \ - contrib/medusa \ - contrib/minicom \ - contrib/mkinitrd \ - contrib/module-init-tools \ - contrib/monodevelop \ - contrib/mount \ - contrib/mplayer \ - contrib/msynctool \ - contrib/mtx \ - contrib/munin-node \ - contrib/mutt \ - contrib/mysqladmin \ - contrib/ncftp \ - contrib/net-tools \ - contrib/nmap \ - contrib/ntpdate \ - contrib/openldap \ - contrib/openssl \ - contrib/p4 \ - contrib/perl \ - contrib/pine \ - contrib/pkg-config \ - contrib/pkg_install \ - contrib/pkgtools \ - contrib/pm-utils \ - contrib/portupgrade \ - contrib/postfix \ - contrib/postgresql \ - contrib/povray \ - contrib/procps \ - contrib/python \ - contrib/qdbus \ - contrib/qemu \ - contrib/quota-tools \ - contrib/rcs \ - contrib/rdesktop \ - contrib/reportbug \ - contrib/resolvconf \ - contrib/rfkill \ - contrib/ri \ - contrib/rpcdebug \ - contrib/rpm \ - contrib/rpmcheck \ - contrib/rrdtool \ - contrib/rsync \ - contrib/rtcwake \ - contrib/samba \ - contrib/sbcl \ - contrib/screen \ - contrib/service \ - contrib/shadow \ - contrib/sitecopy \ - contrib/smartctl \ - contrib/snownews \ - contrib/sqlite3 \ - contrib/ssh \ - contrib/sshfs \ - contrib/strace \ - contrib/svk \ - contrib/sysctl \ - contrib/sysv-rc \ - contrib/tar \ - contrib/tcpdump \ - contrib/unace \ - contrib/unrar \ - contrib/update-alternatives \ - contrib/util-linux \ - contrib/vncviewer \ - contrib/vpnc \ - contrib/wireless-tools \ - contrib/wodim \ - contrib/wol \ - contrib/wtf \ - contrib/wvdial \ - contrib/xhost \ - contrib/xm \ - contrib/xmllint \ - contrib/xmlwf \ - contrib/xmms \ - contrib/xrandr \ - contrib/xsltproc \ - contrib/xz \ - contrib/yp-tools \ - contrib/yum-arch - profiledir = $(sysconfdir)/profile.d profile_DATA = bash_completion.sh @@ -178,6 +10,4 @@ bash_completion.sh: bash_completion.sh.in Makefile CLEANFILES = bash_completion.sh -EXTRA_DIST = CHANGES $(sysconf_DATA) $(bashcomp_DATA) bash_completion.sh.in \ - contrib/_mock contrib/_modules contrib/_subversion contrib/_yum \ - contrib/_yum-utils +EXTRA_DIST = CHANGES $(sysconf_DATA) bash_completion.sh.in diff --git a/bash_completion b/bash_completion index ef00f05a..d74e7b79 100644 --- a/bash_completion +++ b/bash_completion @@ -70,7 +70,7 @@ complete -d pushd # START exclude -- do NOT remove this line # bzcmp, bzdiff, bz*grep, bzless, bzmore intentionally not here, see Debian: #455510 complete -f -X '!*.?(t)bz?(2)' bunzip2 bzcat pbunzip2 pbzcat -complete -f -X '!*.@(zip|ZIP|[ejw]ar|[EJW]AR|exe|EXE|pk3|wsz|zargo|xpi|sxw|o[tx]t|od[fgpst]|epub)' unzip zipinfo +complete -f -X '!*.@(zip|[ejw]ar|exe|pk3|wsz|zargo|xpi|sxw|o[tx]t|od[fgpst]|epub)' unzip zipinfo complete -f -X '*.Z' compress znew # zcmp, zdiff, z*grep, zless, zmore intentionally not here, see Debian: #455510 complete -f -X '!*.@(Z|[gGd]z|t[ag]z)' gunzip zcat unpigz @@ -79,33 +79,32 @@ complete -f -X '!*.Z' uncompress complete -f -X '!*.@(tlz|lzma)' lzcat lzegrep lzfgrep lzgrep lzless lzmore unlzma complete -f -X '!*.@(?(t)xz|tlz|lzma)' unxz xzcat complete -f -X '!*.lrz' lrunzip -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 -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 '!*.@(gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx)' ee +complete -f -X '!*.@(gif|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)?(.@(gz|Z|bz2))' kdvi -complete -f -X '!*.@(dvi|DVI)' dvips dviselect dvitype dvipdf advi dvipdfm dvipdfmx -complete -f -X '!*.@(pdf|PDF)' acroread gpdf xpdf -complete -f -X '!*.@(?(e)ps|?(E)PS|pdf|PDF)' kpdf -complete -f -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF|dvi|DVI)?(.gz|.GZ|.bz2|.BZ2)|cb[rz]|CB[RZ]|djv?(u)|DJV?(U)|dvi|DVI|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|fdf|FDF)' evince -complete -f -X '!*.@(okular|@(?(e|x)ps|?(E|X)PS|pdf|PDF|dvi|DVI|cb[rz]|CB[RZ]|djv?(u)|DJV?(U)|dvi|DVI|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|epub|EPUB|odt|ODT|fb|FB|mobi|MOBI|g3|G3|chm|CHM|fdf|FDF)?(.?(gz|GZ|bz2|BZ2)))' okular -complete -f -X '!*.@(?(e)ps|?(E)PS|pdf|PDF)' ps2pdf ps2pdf12 ps2pdf13 ps2pdf14 ps2pdfwr +complete -f -X '!*.@(dvi|DVI)?(.@(gz|Z|bz2))' xdvi kdvi +complete -f -X '!*.dvi' dvips dviselect dvitype dvipdf advi dvipdfm dvipdfmx +complete -f -X '!*.pdf' acroread gpdf xpdf +complete -f -X '!*.@(?(e)ps|pdf)' kpdf +complete -f -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF|dvi|DVI)?(.gz|.GZ|.bz2|.BZ2)|cb[rz]|djv?(u)|gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|fdf)' evince +complete -f -X '!*.@(okular|@(?(e|x)ps|?(E|X)PS|pdf|PDF|dvi|DVI|cb[rz]|CB[RZ]|djv?(u)|DJV?(U)|dvi|DVI|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|epub|EPUB|odt|ODT|fb?(2)|FB?(2)|mobi|MOBI|g3|G3|chm|CHM|fdf|FDF)?(.?(gz|GZ|bz2|BZ2)))' okular +complete -f -X '!*.@(?(e)ps|pdf)' ps2pdf ps2pdf12 ps2pdf13 ps2pdf14 ps2pdfwr complete -f -X '!*.texi*' makeinfo texi2html -complete -f -X '!*.@(?(la)tex|?(LA)TEX|texi|TEXI|dtx|DTX|ins|INS|ltx|LTX)' 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|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp[234]|MP[234]|m4[pv]|M4[PV]|mkv|MKV|og[gmv]|OG[GMV]|t[ps]|T[PS]|wav|WAV|flac|FLAC|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM)|+([0-9]).@(vdr|VDR))' xine aaxine fbxine kaffeine dragon +complete -f -X '!*.@(?(la)tex|texi|dtx|ins|ltx)' tex latex slitex jadetex pdfjadetex pdftex pdflatex texi2dvi +complete -f -X '!*.mp3' mpg123 mpg321 madplay +complete -f -X '!*@(.@(mp?(e)g|MP?(E)G|wma|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp[234]|MP[234]|m4[pv]|M4[PV]|mkv|MKV|og[gmv]|OG[GMV]|t[ps]|T[PS]|wav|WAV|flac|FLAC|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM)|+([0-9]).@(vdr|VDR))?(.part)' xine aaxine fbxine kaffeine dragon 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 '!*.@(ogg|m3u|flac|spx)' ogg123 +complete -f -X '!*.@(mp3|ogg|pls|m3u)' gqmpeg freeamp complete -f -X '!*.fig' xfig -complete -f -X '!*.@(mid?(i)|MID?(I)|cmf|CMF)' 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|s[3t]m|S[3T]M|kar|KAR)' timidity -complete -f -X '!*.@(m[eo]d|M[EO]D|s[3t]m|S[3T]M|xm|XM|it|IT)' modplugplay modplug123 -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)' vi vim gvim rvim view rview rgvim rgview gview emacs xemacs sxemacs kate kwrite +complete -f -X '!*.@(mid?(i)|cmf)' playmidi +complete -f -X '!*.@(mid?(i)|rmi|rcp|[gr]36|g18|mod|xm|it|x3m|s[3t]m|kar)' timidity +complete -f -X '!*.@(m[eo]d|s[3t]m|xm|it)' modplugplay modplug123 +complete -f -X '*.@(o|so|so.!(conf)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)' vi vim gvim rvim view rview rgvim rgview gview emacs xemacs sxemacs kate kwrite complete -f -X '!*.@([eE][xX][eE]?(.[sS][oO])|[cC][oO][mM]|[sS][cC][rR])' wine -complete -f -X '!*.@(zip|ZIP|z|Z|gz|GZ|tgz|TGZ)' bzme +complete -f -X '!*.@(zip|z|gz|tgz)' bzme # konqueror not here on purpose, it's more than a web/html browser complete -f -X '!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))' netscape mozilla lynx opera galeon dillo elinks amaya firefox mozilla-firefox iceweasel google-chrome chromium-browser epiphany complete -f -X '!*.@(sxw|stw|sxg|sgl|doc?([mx])|dot?([mx])|rtf|txt|htm|html|odt|ott|odm)' oowriter @@ -114,14 +113,13 @@ complete -f -X '!*.@(sxc|stc|xls?([bmx])|xlw|xlt?([mx])|[ct]sv|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 +complete -f -X '!*.[rs]pm' rpm2cpio complete -f -X '!*.aux' bibtex complete -f -X '!*.po' poedit gtranslator kbabel lokalize complete -f -X '!*.@([Pp][Rr][Gg]|[Cc][Ll][Pp])' harbour gharbour hbpp complete -f -X '!*.[Hh][Rr][Bb]' hbrun complete -f -X '!*.ly' lilypond ly2dvi complete -f -X '!*.@(dif?(f)|?(d)patch)?(.@([gx]z|bz2|lzma))' cdiff -complete -f -X '!*.@(dif?(f)|?(d)patch)' kompare complete -f -X '!*.lyx' lyx # FINISH exclude -- do not remove this line @@ -310,7 +308,7 @@ __reassemble_comp_words_by_ref() { ref="$2[$j]" eval $2[$j]=\${!ref}\${COMP_WORDS[i]} # Indicate new cword - [[ $i == $COMP_CWORD && ${COMP_WORDS[i]} ]] && eval $3=$j + [[ $i == $COMP_CWORD ]] && eval $3=$j done else # No, list of word completions separators hasn't changed; @@ -612,11 +610,12 @@ _quote_readline_by_ref() # This function performs file and directory completion. It's better than # simply using 'compgen -f', because it honours spaces in filenames. # @param $1 If `-d', complete only on directories. Otherwise filter/pick only -# completions with `.$1' as file extension. +# completions with `.$1' and the uppercase version of it as file +# extension. # _filedir() { - local i IFS=$'\t\n' xspec + local i IFS=$'\n' xspec _tilde "$cur" || return 0 @@ -638,47 +637,16 @@ _filedir() )) if [[ "$1" != -d ]]; then - xspec=${1:+"!*.$1"} + # Munge xspec to contain uppercase version too + [[ ${BASH_VERSINFO[0]} -ge 4 ]] && \ + xspec=${1:+"!*.@($1|${1^^})"} || \ + xspec=${1:+"!*.@($1|$(printf %s $1 | tr '[:lower:]' '[:upper:]'))"} toks=( ${toks[@]-} $( compgen -f -X "$xspec" -- $quoted) ) if [ ${#toks[@]} -ne 0 ]; then - # If `compopt' is available, set `-o filenames' - type compopt &>/dev/null && compopt -o filenames || - # No, `compopt' isn't available; - # Is `-o filenames' set? - [[ ( - ${COMP_WORDS[0]} && - "$(complete -p ${COMP_WORDS[0]})" == *"-o filenames"* - ) ]] || { - # No, `-o filenames' isn't set; - # Emulate `-o filenames' - # NOTE: A side-effect of emulating `-o filenames' is that - # backslash escape characters are visible within the list - # of presented completions, e.g. the completions look - # like: - # - # $ foo a - # a\ b/ a\$b/ - # - # whereas with `-o filenames' active the completions look - # like: - # - # $ ls a - # a b/ a$b/ - # - for ((i=0; i < ${#toks[@]}; i++)); do - # If directory exists, append slash (/) - if [[ ${cur:0:1} != "'" ]]; then - [[ -d ${toks[i]} ]] && toks[i]="${toks[i]}"/ - if [[ ${cur:0:1} == '"' ]]; then - toks[i]=${toks[i]//\\/\\\\} - toks[i]=${toks[i]//\"/\\\"} - toks[i]=${toks[i]//\$/\\\$} - else - toks[i]=$(printf %q ${toks[i]}) - fi - fi - done - } + # Turn on -o filenames; see http://bugs.debian.org/272660#64 for + # info about the compgen hack (bash < 4) + compopt -o filenames 2>/dev/null || \ + compgen -f /non-existing-dir/ >/dev/null fi fi @@ -703,13 +671,13 @@ _split_longopt() return 1 } -# This function tries to parse the output of $command --help +# This function tries to parse the help output of the given command. +# @param $1 command +# @param $2 command options (default: --help) # _parse_help() { - local cmd - cmd=$1 - $cmd --help 2>&1 | command grep -- "^[[:space:]]*-" | tr "," " " | \ - awk '{print $1; if ($2 ~ /-.*/) { print $2 } }' | sed -e "s:=.*::g" + $1 ${2:---help} 2>&1 | sed -e '/^[[:space:]]*-/!d' -e 's|[,/]| |g' | \ + awk '{ print $1; if ($2 ~ /^-/) { print $2 } }' | sed -e 's|=.*||' } # This function completes on signal names @@ -1276,16 +1244,16 @@ _known_hosts_real() awkcur=${awkcur//\./\\\.} curd=$awkcur - if [[ "$awkcur" == [0-9]*.* ]]; then - # Digits followed by a dot - just search for that - awkcur="^$awkcur.*" + if [[ "$awkcur" == [0-9]*[.:]* ]]; then + # Digits followed by a dot or a colon - just search for that + awkcur="^$awkcur[.:]*" elif [[ "$awkcur" == [0-9]* ]]; then - # Digits followed by no dot - search for digits followed - # by a dot - awkcur="^$awkcur.*\." + # Digits followed by no dot or colon - search for digits followed + # by a dot or a colon + awkcur="^$awkcur.*[.:]" elif [ -z "$awkcur" ]; then - # A blank - search for a dot or an alpha character - awkcur="[a-z.]" + # A blank - search for a dot, a colon, or an alpha character + awkcur="[a-z.:]" else awkcur="^$awkcur" fi @@ -1294,9 +1262,8 @@ _known_hosts_real() # FS needs to look for a comma separated list COMPREPLY=( "${COMPREPLY[@]}" $( awk 'BEGIN {FS=","} /^\s*[^|\#]/ {for (i=1; i<=2; ++i) { \ - gsub(" .*$", "", $i); \ - gsub("[\\[\\]]", "", $i); \ - gsub(":[0-9]+$", "", $i); \ + sub(" .*$", "", $i); \ + sub("^\\[", "", $i); sub("\\](:[0-9]+)?$", "", $i); \ if ($i ~ /'"$awkcur"'/) {print $i} \ }}' "${kh[@]}" 2>/dev/null ) ) fi @@ -1359,7 +1326,7 @@ complete -F _known_hosts traceroute traceroute6 tracepath tracepath6 ping \ # _cd() { - local cur IFS=$'\t\n' i j k + local cur IFS=$'\n' i j k _get_comp_words_by_ref cur # try to allow variable completion @@ -1368,8 +1335,10 @@ _cd() return 0 fi - # Enable -o filenames option, see Debian bug #272660 - compgen -f /non-existing-dir/ >/dev/null + # Turn on -o filenames; see http://bugs.debian.org/272660#64 for + # info about the compgen hack (bash < 4) + compopt -o filenames 2>/dev/null || \ + compgen -f /non-existing-dir/ >/dev/null # Use standard dir completion if no CDPATH or parameter starts with /, # ./ or ../ @@ -1382,7 +1351,7 @@ _cd() local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y) # we have a CDPATH, so loop on its contents - for i in ${CDPATH//:/$'\t'}; do + for i in ${CDPATH//:/$'\n'}; do # create an array of matched subdirs k="${#COMPREPLY[@]}" for j in $( compgen -d $i/$cur ); do @@ -1562,7 +1531,7 @@ _filedir_xspec() { local IFS cur xspec - IFS=$'\t\n' + IFS=$'\n' COMPREPLY=() _get_comp_words_by_ref cur @@ -1587,8 +1556,19 @@ _filedir_xspec() } )) + # Munge xspec to contain uppercase version too + eval xspec="${xspec}" + local matchop=! + if [[ $xspec == !* ]]; then + xspec=${xspec#!} + matchop=@ + fi + [[ ${BASH_VERSINFO[0]} -ge 4 ]] && \ + xspec="$matchop($xspec|${xspec^^})" || \ + xspec="$matchop($xspec|$(printf %s $xspec | tr '[:lower:]' '[:upper:]'))" + toks=( ${toks[@]-} $( - eval compgen -f -X "$xspec" -- "\$(quote_readline "\$cur")" | { + eval compgen -f -X "!$xspec" -- "\$(quote_readline "\$cur")" | { while read -r tmp; do [ -n $tmp ] && printf '%s\n' $tmp done @@ -1625,8 +1605,8 @@ if [[ -d $BASH_COMPLETION_COMPAT_DIR && -r $BASH_COMPLETION_COMPAT_DIR && \ -x $BASH_COMPLETION_COMPAT_DIR ]]; then for i in $(LC_ALL=C command ls "$BASH_COMPLETION_COMPAT_DIR"); do i=$BASH_COMPLETION_COMPAT_DIR/$i - [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)) \ - && ( -f $i || -h $i ) && -r $i ]] && . "$i" + [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)|Makefile*) \ + && -f $i && -r $i ]] && . "$i" done fi if [[ $BASH_COMPLETION_DIR != $BASH_COMPLETION_COMPAT_DIR && \ @@ -1634,8 +1614,8 @@ if [[ $BASH_COMPLETION_DIR != $BASH_COMPLETION_COMPAT_DIR && \ -x $BASH_COMPLETION_DIR ]]; then for i in $(LC_ALL=C command ls "$BASH_COMPLETION_DIR"); do i=$BASH_COMPLETION_DIR/$i - [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)) \ - && ( -f $i || -h $i ) && -r $i ]] && . "$i" + [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)|Makefile*) \ + && -f $i && -r $i ]] && . "$i" done fi unset i diff --git a/completions/Makefile.am b/completions/Makefile.am new file mode 100644 index 00000000..5c904295 --- /dev/null +++ b/completions/Makefile.am @@ -0,0 +1,176 @@ +bashcomp_DATA = abook \ + ant \ + apache2ctl \ + apt \ + apt-build \ + aptitude \ + aspell \ + autorpm \ + bash-builtins \ + bind-utils \ + bitkeeper \ + bittorrent \ + bluez \ + brctl \ + bzip2 \ + cardctl \ + cfengine \ + chkconfig \ + chsh \ + cksfv \ + clisp \ + configure \ + coreutils \ + cowsay \ + cpan2dist \ + cpio \ + crontab \ + cups \ + cryptsetup \ + cvs \ + cvsps \ + dd \ + dhclient \ + dict \ + dpkg \ + dselect \ + dsniff \ + e2fsprogs \ + findutils \ + freeciv \ + freerdp \ + fuse \ + gcc \ + gcl \ + gdb \ + genisoimage \ + getent \ + gkrellm \ + gnatmake \ + gpg \ + gpg2 \ + gzip \ + heimdal \ + hping2 \ + iconv \ + iftop \ + ifupdown \ + imagemagick \ + info \ + iptables \ + ipmitool \ + ipsec \ + ipv6calc \ + isql \ + jar \ + java \ + k3b \ + kldload \ + larch \ + ldapvi \ + lftp \ + lilo \ + links \ + lintian \ + lisp \ + lrzip \ + lvm \ + lzma \ + lzop \ + mailman \ + make \ + man \ + mc \ + mcrypt \ + mdadm \ + medusa \ + minicom \ + mkinitrd \ + module-init-tools \ + monodevelop \ + mount \ + mplayer \ + msynctool \ + mtx \ + munin-node \ + mutt \ + mysqladmin \ + ncftp \ + net-tools \ + nmap \ + ntpdate \ + openldap \ + openssl \ + p4 \ + perl \ + pine \ + pkg-config \ + pkg_install \ + pkgtools \ + pm-utils \ + portupgrade \ + postfix \ + postgresql \ + povray \ + procps \ + python \ + qdbus \ + qemu \ + quota-tools \ + rcs \ + rdesktop \ + reportbug \ + resolvconf \ + rfkill \ + ri \ + rpcdebug \ + rpm \ + rpmcheck \ + rrdtool \ + rsync \ + rtcwake \ + samba \ + sbcl \ + screen \ + service \ + sh \ + shadow \ + sitecopy \ + smartctl \ + snownews \ + sqlite3 \ + ssh \ + sshfs \ + strace \ + svk \ + sysbench \ + sysctl \ + sysv-rc \ + tar \ + tcpdump \ + unace \ + unrar \ + update-alternatives \ + util-linux \ + vncviewer \ + vpnc \ + wireless-tools \ + wodim \ + wol \ + wtf \ + wvdial \ + xhost \ + xm \ + xmllint \ + xmlwf \ + xmms \ + xmodmap \ + xrandr \ + xrdb \ + xsltproc \ + xz \ + yp-tools \ + yum-arch + +EXTRA_DIST = $(bashcomp_DATA) \ + _mock _modules _subversion _yum _yum-utils diff --git a/contrib/_mock b/completions/_mock similarity index 98% rename from contrib/_mock rename to completions/_mock index f16f116d..40e422ce 100644 --- a/contrib/_mock +++ b/completions/_mock @@ -72,7 +72,7 @@ _mock() --sources --verbose --quiet --trace --enable-plugin \ --disable-plugin --print-root-path' -- "$cur" ) ) else - _filedir '?(no)src.rpm' + _filedir '@(?(no)src.r|s)pm' fi } && complete -F _mock -o filenames mock diff --git a/contrib/_modules b/completions/_modules similarity index 100% rename from contrib/_modules rename to completions/_modules diff --git a/contrib/_subversion b/completions/_subversion similarity index 100% rename from contrib/_subversion rename to completions/_subversion diff --git a/contrib/_yum b/completions/_yum similarity index 100% rename from contrib/_yum rename to completions/_yum diff --git a/contrib/_yum-utils b/completions/_yum-utils similarity index 100% rename from contrib/_yum-utils rename to completions/_yum-utils diff --git a/contrib/abook b/completions/abook similarity index 100% rename from contrib/abook rename to completions/abook diff --git a/contrib/ant b/completions/ant similarity index 100% rename from contrib/ant rename to completions/ant diff --git a/contrib/apache2ctl b/completions/apache2ctl similarity index 100% rename from contrib/apache2ctl rename to completions/apache2ctl diff --git a/contrib/apt b/completions/apt similarity index 100% rename from contrib/apt rename to completions/apt diff --git a/contrib/apt-build b/completions/apt-build similarity index 100% rename from contrib/apt-build rename to completions/apt-build diff --git a/contrib/aptitude b/completions/aptitude similarity index 100% rename from contrib/aptitude rename to completions/aptitude diff --git a/contrib/aspell b/completions/aspell similarity index 100% rename from contrib/aspell rename to completions/aspell diff --git a/contrib/autorpm b/completions/autorpm similarity index 100% rename from contrib/autorpm rename to completions/autorpm diff --git a/contrib/bash-builtins b/completions/bash-builtins similarity index 85% rename from contrib/bash-builtins rename to completions/bash-builtins index aac75ae0..3eba8a11 100644 --- a/contrib/bash-builtins +++ b/completions/bash-builtins @@ -85,10 +85,9 @@ _complete() ;; -A) - COMPREPLY=( $( compgen -W 'alias arrayvar binding \ - builtin command directory disabled enabled \ - export file function group helptopic hostname \ - job keyword running service setopt shopt \ + 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 ;; @@ -111,13 +110,14 @@ _complete() if [[ "$cur" == -* ]]; then # relevant options completion - COMPREPLY=( $( compgen -W '-a -b -c -d -e -f -g -j -k -o -s -v -u -A \ - -G -W -P -S -X -F -C' -- "$cur" ) ) + local opts="-a -b -c -d -e -f -g -j -k -o -s -u -v -A -G -W -P -S -X" + [[ $1 != compgen ]] && opts="$opts -F -C" + COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) ) else COMPREPLY=( $( compgen -A command -- "$cur" ) ) fi } -complete -F _complete complete +complete -F _complete compgen complete # Local variables: # mode: shell-script diff --git a/contrib/bind-utils b/completions/bind-utils similarity index 100% rename from contrib/bind-utils rename to completions/bind-utils diff --git a/contrib/bitkeeper b/completions/bitkeeper similarity index 100% rename from contrib/bitkeeper rename to completions/bitkeeper diff --git a/contrib/bittorrent b/completions/bittorrent similarity index 100% rename from contrib/bittorrent rename to completions/bittorrent diff --git a/contrib/bluez b/completions/bluez similarity index 100% rename from contrib/bluez rename to completions/bluez diff --git a/contrib/brctl b/completions/brctl similarity index 100% rename from contrib/brctl rename to completions/brctl diff --git a/contrib/bzip2 b/completions/bzip2 similarity index 98% rename from contrib/bzip2 rename to completions/bzip2 index f4902e29..be030274 100644 --- a/contrib/bzip2 +++ b/completions/bzip2 @@ -21,7 +21,7 @@ _bzip2() return 0 fi - local IFS=$'\t\n' + local IFS=$'\n' xspec="*.bz2" if [[ "$prev" == --* ]]; then diff --git a/contrib/cardctl b/completions/cardctl similarity index 100% rename from contrib/cardctl rename to completions/cardctl diff --git a/contrib/cfengine b/completions/cfengine similarity index 100% rename from contrib/cfengine rename to completions/cfengine diff --git a/contrib/chkconfig b/completions/chkconfig similarity index 100% rename from contrib/chkconfig rename to completions/chkconfig diff --git a/contrib/chsh b/completions/chsh similarity index 100% rename from contrib/chsh rename to completions/chsh diff --git a/contrib/cksfv b/completions/cksfv similarity index 100% rename from contrib/cksfv rename to completions/cksfv diff --git a/contrib/clisp b/completions/clisp similarity index 100% rename from contrib/clisp rename to completions/clisp diff --git a/contrib/configure b/completions/configure similarity index 100% rename from contrib/configure rename to completions/configure diff --git a/contrib/coreutils b/completions/coreutils similarity index 100% rename from contrib/coreutils rename to completions/coreutils diff --git a/contrib/cowsay b/completions/cowsay similarity index 100% rename from contrib/cowsay rename to completions/cowsay diff --git a/contrib/cpan2dist b/completions/cpan2dist similarity index 100% rename from contrib/cpan2dist rename to completions/cpan2dist diff --git a/contrib/cpio b/completions/cpio similarity index 100% rename from contrib/cpio rename to completions/cpio diff --git a/contrib/crontab b/completions/crontab similarity index 100% rename from contrib/crontab rename to completions/crontab diff --git a/contrib/cryptsetup b/completions/cryptsetup similarity index 100% rename from contrib/cryptsetup rename to completions/cryptsetup diff --git a/contrib/cups b/completions/cups similarity index 100% rename from contrib/cups rename to completions/cups diff --git a/contrib/cvs b/completions/cvs similarity index 100% rename from contrib/cvs rename to completions/cvs diff --git a/contrib/cvsps b/completions/cvsps similarity index 100% rename from contrib/cvsps rename to completions/cvsps diff --git a/contrib/dd b/completions/dd similarity index 100% rename from contrib/dd rename to completions/dd diff --git a/contrib/dhclient b/completions/dhclient similarity index 100% rename from contrib/dhclient rename to completions/dhclient diff --git a/contrib/dict b/completions/dict similarity index 100% rename from contrib/dict rename to completions/dict diff --git a/contrib/dpkg b/completions/dpkg similarity index 100% rename from contrib/dpkg rename to completions/dpkg diff --git a/contrib/dselect b/completions/dselect similarity index 100% rename from contrib/dselect rename to completions/dselect diff --git a/contrib/dsniff b/completions/dsniff similarity index 100% rename from contrib/dsniff rename to completions/dsniff diff --git a/completions/e2fsprogs b/completions/e2fsprogs new file mode 100644 index 00000000..1a240f1b --- /dev/null +++ b/completions/e2fsprogs @@ -0,0 +1,179 @@ +# bash completion for e2fsprogs + +have badblocks && +_badblocks() +{ + COMPREPLY=() + local cur prev + _get_comp_words_by_ref cur prev + + case $prev in + -b|-c|-e|-d|-p|-t) + return 0 + ;; + -i|-o) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + # -w (dangerous) and -X (internal use) not here on purpose + COMPREPLY=( $( compgen -W '-b -c -e -d -f -i -n -o -p -s -t -v' \ + -- "$cur" ) ) + return 0 + fi + + cur=${cur:=/dev/} + _filedir +} && +complete -F _badblocks -o filenames badblocks + + +have dumpe2fs && +_dumpe2fs() +{ + COMPREPLY=() + local cur prev + _get_comp_words_by_ref cur prev + + case $prev in + -o|-V) + return 0 + ;; + -i) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-b -o -f -h -i -x -V' -- "$cur" ) ) + return 0 + fi + + cur=${cur:=/dev/} + _filedir +} && +complete -F _dumpe2fs -o filenames dumpe2fs + + +have e2freefrag && +_e2freefrag() +{ + COMPREPLY=() + local cur prev + _get_comp_words_by_ref cur prev + + case $prev in + -c|-h) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-c -h' -- "$cur" ) ) + return 0 + fi + + cur=${cur:=/dev/} + _filedir +} && +complete -F _e2freefrag -o filenames e2freefrag + + +have e2label && +_e2label() +{ + COMPREPLY=() + local cur cword + _get_comp_words_by_ref cur cword + + if [ $cword -eq 1 ]; then + cur=${cur:=/dev/} + _filedir + fi +} && +complete -F _e2label -o filenames e2label + + +have filefrag && +_filefrag() +{ + COMPREPLY=() + local cur + _get_comp_words_by_ref cur + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-B -b -s -v -x' -- "$cur" ) ) + return 0 + fi + + _filedir +} && +complete -F _filefrag -o filenames filefrag + + +have tune2fs && +_tune2fs() +{ + COMPREPLY=() + local cur prev + _get_comp_words_by_ref cur prev + + case $prev in + -c|-C|-E|-i|-J|-L|-m|-r|-T) + return 0 + ;; + -e) + COMPREPLY=( $( compgen -W 'continue remount-ro panic' -- "$cur" ) ) + return 0 + ;; + -g) + _gids + COMPREPLY=( $( compgen -g -W '${COMPREPLY[@]}' -- "$cur" ) ) + return 0 + ;; + -M) + _filedir -d + ;; + -o) + local -a opts=(^debug ^bsdgroups ^user_xattr ^acl ^uid16 + ^journal_data ^journal_data_ordered ^journal_data_writeback) + COMPREPLY=( $( compgen -W '${opts[@]} ${opts[@]#^}' -- "$cur" ) ) + return 0 + ;; + -O) + local -a opts=(^dir_index ^filetype ^flex_bg ^has_journal + ^large_file ^resize_inode ^sparse_super ^uninit_bg) + COMPREPLY=( $( compgen -W '${opts[@]} ${opts[@]#^}' -- "$cur" ) ) + return 0 + ;; + -u) + _uids + COMPREPLY=( $( compgen -u -W '${COMPREPLY[@]}' -- "$cur" ) ) + return 0 + ;; + -U) + COMPREPLY=( $( compgen -W 'clear random time' -- "$cur" ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-c -C -e -E -f -g -i -j -J -l -L -m -M -o + -O -r -T -u -U' -- "$cur" ) ) + fi + + cur=${cur:=/dev/} + _filedir +} && +complete -F _tune2fs -o filenames tune2fs + +# Local variables: +# mode: shell-script +# sh-basic-offset: 4 +# sh-indent-comment: t +# indent-tabs-mode: nil +# End: +# ex: ts=4 sw=4 et filetype=sh diff --git a/contrib/findutils b/completions/findutils similarity index 100% rename from contrib/findutils rename to completions/findutils diff --git a/contrib/freeciv b/completions/freeciv similarity index 100% rename from contrib/freeciv rename to completions/freeciv diff --git a/completions/freerdp b/completions/freerdp new file mode 100644 index 00000000..82a46462 --- /dev/null +++ b/completions/freerdp @@ -0,0 +1,47 @@ +# bash completion for xfreerdp + +have xfreerdp && +_xfreerdp() +{ + local cur prev + + COMPREPLY=() + _get_comp_words_by_ref cur prev + + case $prev in + -k) + COMPREPLY=( $( compgen -W "$(xfreerdp --kbd-list | \ + awk '/^0x/ {print $1}')" -- "$cur" ) ) + return 0 + ;; + -a) + COMPREPLY=( $( compgen -W '8 15 16 24 32' -- "$cur" ) ) + return 0 + ;; + -x) + COMPREPLY=( $( compgen -W 'b broadband m modem l lan' -- $cur ) ) + return 0 + ;; + --plugin) + COMPREPLY=( $( compgen -W 'cliprdr rdpsnd rdpdr' -- "$cur" ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-u -d -s -c -p -n -t -g -a -z -f -x -O -o \ + -k --kbd-list -h --plugin --data' -- "$cur" ) ) + else + _known_hosts_real "$cur" + fi + +} && +complete -F _xfreerdp xfreerdp + +# Local variables: +# mode: shell-script +# sh-basic-offset: 4 +# sh-indent-comment: t +# indent-tabs-mode: nil +# End: +# ex: ts=4 sw=4 et filetype=sh diff --git a/contrib/fuse b/completions/fuse similarity index 100% rename from contrib/fuse rename to completions/fuse diff --git a/contrib/gcc b/completions/gcc similarity index 100% rename from contrib/gcc rename to completions/gcc diff --git a/contrib/gcl b/completions/gcl similarity index 100% rename from contrib/gcl rename to completions/gcl diff --git a/contrib/gdb b/completions/gdb similarity index 100% rename from contrib/gdb rename to completions/gdb diff --git a/contrib/genisoimage b/completions/genisoimage similarity index 100% rename from contrib/genisoimage rename to completions/genisoimage diff --git a/contrib/getent b/completions/getent similarity index 100% rename from contrib/getent rename to completions/getent diff --git a/contrib/gkrellm b/completions/gkrellm similarity index 100% rename from contrib/gkrellm rename to completions/gkrellm diff --git a/contrib/gnatmake b/completions/gnatmake similarity index 100% rename from contrib/gnatmake rename to completions/gnatmake diff --git a/contrib/gpg b/completions/gpg similarity index 100% rename from contrib/gpg rename to completions/gpg diff --git a/contrib/gpg2 b/completions/gpg2 similarity index 100% rename from contrib/gpg2 rename to completions/gpg2 diff --git a/contrib/gzip b/completions/gzip similarity index 98% rename from contrib/gzip rename to completions/gzip index 0951f72f..afd647ed 100644 --- a/contrib/gzip +++ b/completions/gzip @@ -21,7 +21,7 @@ _gzip() return 0 fi - local IFS=$'\t\n' + local IFS=$'\n' xspec="*.@(gz|t[ag]z)" if [[ "$prev" == --* ]]; then diff --git a/contrib/heimdal b/completions/heimdal similarity index 100% rename from contrib/heimdal rename to completions/heimdal diff --git a/contrib/hping2 b/completions/hping2 similarity index 100% rename from contrib/hping2 rename to completions/hping2 diff --git a/contrib/iconv b/completions/iconv similarity index 100% rename from contrib/iconv rename to completions/iconv diff --git a/completions/iftop b/completions/iftop new file mode 100644 index 00000000..eefcf9c6 --- /dev/null +++ b/completions/iftop @@ -0,0 +1,35 @@ +# iftop(8) completion + +have iftop && +_iftop() +{ + COMPREPLY=() + local cur prev + _get_comp_words_by_ref cur prev + + case $prev in + -h|-f|-F|-m) + return 0 + ;; + -i) + _available_interfaces -a + return 0 + ;; + -c) + _filedir + return 0 + ;; + esac + + COMPREPLY=( $( compgen -W '-h -n -N -p -P -b -B -i -f -F -c -m' \ + -- "$cur" ) ) +} && +complete -F _iftop -o filenames iftop + +# Local variables: +# mode: shell-script +# sh-basic-offset: 4 +# sh-indent-comment: t +# indent-tabs-mode: nil +# End: +# ex: ts=4 sw=4 et filetype=sh diff --git a/contrib/ifupdown b/completions/ifupdown similarity index 100% rename from contrib/ifupdown rename to completions/ifupdown diff --git a/contrib/imagemagick b/completions/imagemagick similarity index 100% rename from contrib/imagemagick rename to completions/imagemagick diff --git a/contrib/info b/completions/info similarity index 100% rename from contrib/info rename to completions/info diff --git a/completions/ipmitool b/completions/ipmitool new file mode 100644 index 00000000..7af8da88 --- /dev/null +++ b/completions/ipmitool @@ -0,0 +1,214 @@ +# bash completion for ipmitool + +have ipmitool && { + +_ipmitool_singleline_help() +{ + COMPREPLY=( $( compgen -W "$( $1 $2 2>&1 | \ + sed -ne 's/[,\r]//g' -e 's/^.*[Cc]ommands://p' )" -- "$cur" ) ) +} + +_ipmitool() +{ + local cur prev + + COMPREPLY=() + _get_comp_words_by_ref cur prev + + case $prev in + -h|-V|-p|-U|-e|-k|-y|-P|-m|-b|-t|-B|-T|-l) + return 0 + ;; + -d) + COMPREPLY=( $( compgen -W "$( \ + command ls -d /dev/ipmi* /dev/ipmi/* /dev/ipmidev/* \ + 2>/dev/null | sed -ne 's/^[^0-9]*\([0-9]\{1,\}\)/\1/p' )" \ + -- "$cur" ) ) + return 0 + ;; + -I) + COMPREPLY=( $( compgen -W "$( $1 -h 2>&1 | \ + sed -e '/^Interfaces:/,/^[[:space:]]*$/!d' \ + -ne 's/^[[:space:]]\{1,\}\([^[:space:]]\{1,\}\).*/\1/p' )" \ + -- "$cur" ) ) + return 0 + ;; + -H) + _known_hosts_real "$cur" + return 0 + ;; + -f|-S|-O) + _filedir + return 0 + ;; + -C) + COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9 10 11 12 13 14' \ + -- "$cur" ) ) + return 0 + ;; + -L) + COMPREPLY=( $( compgen -W 'CALLBACK USER OPERATOR ADMINISTRATOR' \ + -- "$cur" ) ) + return 0 + ;; + -A) + COMPREPLY=( $( compgen -W 'NONE PASSWORD MD2 MD5 OEM' -- "$cur" ) ) + return 0 + ;; + -o) + COMPREPLY=( $( compgen -W "$( $1 -o list 2>&1 | \ + awk '/^[ \t]+/ { print $1 }' ) list" -- "$cur" ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-h -V -v -c -d -I -H -p -U -f -S -a \ + -e -C -k -y -L -A -P -E -K -m -b -t -B -T -l -o -O' -- "$cur" ) ) + return 0 + fi + + # Find out command and subcommand + + local cmds=( raw i2c spd lan chassis power event mc sdr sensor fru gendev + sel pef sol tsol isol user channel session sunoem kontronoem picmg fwum + firewall shell exec set hpm ekanalyzer) + local i c cmd subcmd + for (( i=1; i < ${#COMP_WORDS[@]}-1; i++ )); do + [[ -n $cmd ]] && subcmd=${COMP_WORDS[i]} && break + for c in ${cmds[@]}; do + [ ${COMP_WORDS[i]} = $c ] && cmd=$c && break + done + done + + if [ -z "$cmd" ]; then + COMPREPLY=( $( compgen -W '${cmds[@]}' -- "$cur" ) ) + return 0 + fi + + # Command/subcommand completions + + case $cmd in + + shell) + ;; + + exec) + _filedir + ;; + + chassis|power|kontronoem|fwum) + _ipmitool_singleline_help $1 $cmd + ;; + + lan) + case $subcmd in + print|set) + ;; + alert) + [ "$prev" = alert ] && \ + COMPREPLY=( $( compgen -W 'print set' -- "$cur" ) ) + ;; + stats) + [ "$prev" = stats ] && \ + COMPREPLY=( $( compgen -W 'print set' -- "$cur" ) ) + ;; + *) + COMPREPLY=( $( compgen -W 'print set alert stats' \ + -- "$cur" ) ) + ;; + esac + ;; + + sdr) + case $subcmd in + get|info|type|list|entity) + ;; + elist) + COMPREPLY=( $( compgen -W 'all full compact event mclog fru + generic' -- "$cur" ) ) + ;; + dump) + _filedir + ;; + fill) + case $prev in + fill) + COMPREPLY=( $( compgen -W 'sensors file' \ + -- "$cur" ) ) + ;; + file) + _filedir + ;; + esac + ;; + *) + COMPREPLY=( $( compgen -W 'get info type list elist entity + dump fill' -- "$cur" ) ) + ;; + esac + ;; + + sensor) + case $subcmd in + list|get|thresh) + ;; + *) + COMPREPLY=( $( compgen -W 'list get thresh' -- "$cur" ) ) + ;; + esac + ;; + + sel) + case $subcmd in + info|clear|list|elist|delete) + ;; + add|save|writeraw|readraw) + _filedir + ;; + time) + [ "$prev" = time ] && \ + COMPREPLY=( $( compgen -W 'get set' -- "$cur" ) ) + ;; + *) + COMPREPLY=( $( compgen -W 'info clear list elist delete add + get save writeraw readraw time' -- "$cur" ) ) + ;; + esac + ;; + + user) + case $subcmd in + summary|list|disable|enable|priv|test) + ;; + set) + [ "$prev" = set ] && \ + COMPREPLY=( $( compgen -W 'name password' -- "$cur" ) ) + ;; + *) + COMPREPLY=( $( compgen -W 'summary list set disable enable + priv test' -- "$cur" ) ) + ;; + esac + ;; + + set) + [ "$prev" = set ] && \ + COMPREPLY=( $( compgen -W 'hostname username password privlvl + authtype localaddr targetaddr port csv verbose' \ + -- "$cur" ) ) + ;; + + esac +} + +} && +complete -F _ipmitool -o filenames ipmitool + +# Local variables: +# mode: shell-script +# sh-basic-offset: 4 +# sh-indent-comment: t +# indent-tabs-mode: nil +# End: +# ex: ts=4 sw=4 et filetype=sh diff --git a/contrib/ipsec b/completions/ipsec similarity index 100% rename from contrib/ipsec rename to completions/ipsec diff --git a/contrib/iptables b/completions/iptables similarity index 100% rename from contrib/iptables rename to completions/iptables diff --git a/contrib/ipv6calc b/completions/ipv6calc similarity index 100% rename from contrib/ipv6calc rename to completions/ipv6calc diff --git a/contrib/isql b/completions/isql similarity index 100% rename from contrib/isql rename to completions/isql diff --git a/contrib/jar b/completions/jar similarity index 91% rename from contrib/jar rename to completions/jar index 75dcaf3e..6abfff3d 100644 --- a/contrib/jar +++ b/completions/jar @@ -18,7 +18,7 @@ _jar() _filedir ;; *f) - _filedir '?([ejw]ar|zip|[EJW]AR|ZIP)' + _filedir '@([ejw]ar|zip)' ;; *) _filedir diff --git a/contrib/java b/completions/java similarity index 100% rename from contrib/java rename to completions/java diff --git a/contrib/k3b b/completions/k3b similarity index 100% rename from contrib/k3b rename to completions/k3b diff --git a/contrib/kldload b/completions/kldload similarity index 100% rename from contrib/kldload rename to completions/kldload diff --git a/contrib/larch b/completions/larch similarity index 100% rename from contrib/larch rename to completions/larch diff --git a/contrib/ldapvi b/completions/ldapvi similarity index 100% rename from contrib/ldapvi rename to completions/ldapvi diff --git a/contrib/lftp b/completions/lftp similarity index 100% rename from contrib/lftp rename to completions/lftp diff --git a/contrib/lilo b/completions/lilo similarity index 100% rename from contrib/lilo rename to completions/lilo diff --git a/contrib/links b/completions/links similarity index 100% rename from contrib/links rename to completions/links diff --git a/contrib/lintian b/completions/lintian similarity index 100% rename from contrib/lintian rename to completions/lintian diff --git a/contrib/lisp b/completions/lisp similarity index 100% rename from contrib/lisp rename to completions/lisp diff --git a/contrib/lrzip b/completions/lrzip similarity index 98% rename from contrib/lrzip rename to completions/lrzip index e5848035..445fc3c5 100644 --- a/contrib/lrzip +++ b/completions/lrzip @@ -48,7 +48,7 @@ _lrzip() _expand || return 0 - local IFS=$'\t\n' + local IFS=$'\n' COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \ $( compgen -d -- "$cur" ) ) } && diff --git a/contrib/lvm b/completions/lvm similarity index 100% rename from contrib/lvm rename to completions/lvm diff --git a/contrib/lzma b/completions/lzma similarity index 98% rename from contrib/lzma rename to completions/lzma index a176f191..c2fece97 100644 --- a/contrib/lzma +++ b/completions/lzma @@ -16,7 +16,7 @@ _lzma() return 0 fi - local IFS=$'\t\n' + local IFS=$'\n' xspec="*.@(lzma|tlz)" if [[ "$prev" == --* ]]; then diff --git a/contrib/lzop b/completions/lzop similarity index 98% rename from contrib/lzop rename to completions/lzop index 19852b24..7a34ae3e 100644 --- a/contrib/lzop +++ b/completions/lzop @@ -53,7 +53,7 @@ _lzop() _expand || return 0 - local IFS=$'\t\n' + local IFS=$'\n' COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \ $( compgen -d -- "$cur" ) ) } && diff --git a/contrib/mailman b/completions/mailman similarity index 100% rename from contrib/mailman rename to completions/mailman diff --git a/contrib/make b/completions/make similarity index 100% rename from contrib/make rename to completions/make diff --git a/contrib/man b/completions/man similarity index 100% rename from contrib/man rename to completions/man diff --git a/contrib/mc b/completions/mc similarity index 100% rename from contrib/mc rename to completions/mc diff --git a/contrib/mcrypt b/completions/mcrypt similarity index 97% rename from contrib/mcrypt rename to completions/mcrypt index e777150f..9e746fb1 100644 --- a/contrib/mcrypt +++ b/completions/mcrypt @@ -58,12 +58,12 @@ _mcrypt() --list-hash --verbose --quiet --help \ --version --license' -- "$cur" ) ) elif [[ ${COMP_WORDS[0]} == mdecrypt ]]; then - _filedir '@(nc)' + _filedir nc else decrypt=0 for (( i=1; i < ${#COMP_WORDS[@]}-1; i++ )); do if [[ ${COMP_WORDS[i]} == -@(d|-decrypt) ]]; then - _filedir '@(nc)' + _filedir nc decrypt=1 break fi diff --git a/contrib/mdadm b/completions/mdadm similarity index 100% rename from contrib/mdadm rename to completions/mdadm diff --git a/contrib/medusa b/completions/medusa similarity index 100% rename from contrib/medusa rename to completions/medusa diff --git a/contrib/minicom b/completions/minicom similarity index 100% rename from contrib/minicom rename to completions/minicom diff --git a/contrib/mkinitrd b/completions/mkinitrd similarity index 100% rename from contrib/mkinitrd rename to completions/mkinitrd diff --git a/contrib/module-init-tools b/completions/module-init-tools similarity index 100% rename from contrib/module-init-tools rename to completions/module-init-tools diff --git a/contrib/monodevelop b/completions/monodevelop similarity index 100% rename from contrib/monodevelop rename to completions/monodevelop diff --git a/contrib/mount b/completions/mount similarity index 100% rename from contrib/mount rename to completions/mount diff --git a/contrib/mplayer b/completions/mplayer similarity index 84% rename from contrib/mplayer rename to completions/mplayer index 2786b7ad..39ac93d3 100644 --- a/contrib/mplayer +++ b/completions/mplayer @@ -4,39 +4,51 @@ have mplayer && { _mplayer_options_list() { cur=${cur%\\} - COMPREPLY=( $( compgen -W "$( $1 $2 help 2>/dev/null | \ - sed -e '1,/^Available/d' | awk '{print $1}' | \ + COMPREPLY=( $( compgen -W "$( $1 -nomsgcolor -nomsgmodule $2 help 2>/dev/null | \ + sed -e '/^Available/,/^$/!d' -e '/^Available/d' | awk '{print $1}' | \ sed -e 's/:$//' -e 's/^'${2#-}'$//' -e 's/<.*//' )" -- "$cur" ) ) } _mplayer() { - local cmd cur prev skinsdir IFS=$' \t\n' i j k=0 + local cmd cur prev i j k=0 COMPREPLY=() cmd=${COMP_WORDS[0]} _get_comp_words_by_ref cur prev case $prev in - -[av][cfo]|-[av]fm|-vop|-fstype|-demuxer|-o[av]c|-of|-profile) + -[av][cfo]|-[av]fm|-vop|-fstype|-demuxer|-o[av]c|-of|-profile| \ + -audio-demuxer|-sub-demuxer) _mplayer_options_list $cmd $prev return 0 ;; - -audiofile) - _filedir '@(mp3|MP3|mpg|MPG|ogg|OGG|w?(a)v|W?(A)V|mid|MID|flac|FLAC|mka|MKA|ape|APE)' + -show-profile) + _mplayer_options_list $cmd -profile return 0 ;; - -font) - _filedir '@(desc|ttf)' + -audiofile) + _filedir '@(mp3|mpg|ogg|w?(a)v|mid|flac|mka|ape)' + return 0 + ;; + -font|-subfont) + if [ "$prev" = -font ]; then + _filedir '@(desc|ttf)' + else + _filedir ttf + fi + local IFS=$'\n' + COMPREPLY=( "${COMPREPLY[@]}" + $( compgen -W '$( fc-list 2>/dev/null )' -- "$cur" ) ) return 0 ;; -sub) - _filedir '@(srt|SRT|sub|SUB|txt|TXT|utf|UTF|rar|RAR|mpsub|smi|js|ssa|SSA|ass|ASS)' + _filedir '@(srt|sub|txt|utf|rar|mpsub|smi|js|ssa|ass)' return 0 ;; -vobsub) - _filedir '@(idx|IDX|ifo|IFO|sub|SUB)' - IFS=$'\t\n' + _filedir '@(idx|ifo|sub)' + local IFS=$'\n' COMPREPLY=( $( for i in "${COMPREPLY[@]}"; do if [[ -f $i && -r $i ]]; then printf '%s\n' ${i%.*} @@ -44,28 +56,28 @@ _mplayer() printf '%s\n' $i fi done ) ) - IFS=$' \t\n' return 0 ;; -ifo) - _filedir '@(ifo|IFO)' + _filedir ifo return 0 ;; -cuefile) - _filedir '@(bin|BIN|cue|CUE)' + _filedir '@(bin|cue)' return 0 ;; -skin) # if you don't have installed mplayer in /usr you # may want to set the MPLAYER_SKINS_DIR global variable + local -a dirs if [ -n "$MPLAYER_SKINS_DIR" ]; then - skinsdir=$MPLAYER_SKINS_DIR + dirs=($MPLAYER_SKINS_DIR) else - skinsdir=/usr/share/mplayer/Skin + dirs=(/usr/share/mplayer/skins /usr/local/share/mplayer/skins) fi - IFS=$'\t\n' - for i in ~/.mplayer/Skin $skinsdir; do + local IFS=$'\n' + for i in ~/.mplayer/skins ${dirs[@]}; do if [[ -d $i && -r $i ]]; then for j in $( compgen -d $i/$cur ); do COMPREPLY[$k]=${j#$i/} @@ -73,7 +85,6 @@ _mplayer() done fi done - IFS=$' \t\n' return 0 ;; -cdrom-device) @@ -97,7 +108,7 @@ _mplayer() return 0 ;; -autoq|-autosync|-loop|-menu-root|-speed|-sstep|-aid|-alang| \ - -audo-demuxer|-sub-demuxer|-demuxer|-bandwidth|-cache|-chapter| \ + -bandwidth|-cache|-chapter| \ -dvd|-dvdangle|-fps|-frames|-mc|-passwd|-user|-sb|-srate|-ss|-vcd| \ -vi|-vid|-vivo|-ffactor|-sid|-slang|-spualign|-spuaa|-spugauss| \ -vobsubid|-delay|-bpp|-brightness|-contrast|-dfbopts|-display| \ @@ -115,7 +126,7 @@ _mplayer() return 0 ;; -lavdopts) - COMPREPLY=( $( compgen -W 'ec er= bug= idct= gray' -- "$cur" ) ) + COMPREPLY=( $( compgen -W 'bitexact bug= debug= ec= er= fast gray idct= lowres= sb= st= skiploopfilter= skipidct= skipframe= threads= vismv= vstats' -- "$cur" ) ) return 0 ;; -lavcopts) @@ -230,13 +241,13 @@ _mplayer() case $cur in -*) - COMPREPLY=( $( compgen -W '$( $cmd -list-options 2>/dev/null | \ + COMPREPLY=( $( compgen -W '$( $cmd -nomsgcolor -nomsgmodule -list-options 2>/dev/null | \ sed -ne '1,/^[[:space:]]*Name/d' \ -e "s/^[[:space:]]*/-/" -e "s/[[:space:]:].*//" \ -e "/^-\(Total\|.*\*\)\{0,1\}$/!p" )' -- "$cur" ) ) ;; *) - _filedir '@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|ASF|vob|VOB|bin|BIN|dat|DAT|vcd|VCD|ps|PS|pes|PES|fl[iv]|FL[IV]|fxm|FXM|viv|VIV|rm?(j)|RM?(J)|ra?(m)|RA?(M)|yuv|YUV|mov|MOV|qt|QT|mp[234]|MP[234]|m4[av]|M4[AV]|og[gmavx]|OG[GMAVX]|w?(a)v|W?(A)V|dump|DUMP|mk[av]|MK[AV]|m4a|M4A|aac|AAC|m[24]v|M[24]V|dv|DV|rmvb|RMVB|mid|MID|t[ps]|T[PS]|3g[p2]|mpc|MPC|flac|FLAC|vro|VRO|divx|DIVX|aif?(f)|AIF?(F)|m2ts|M2TS|vdr|VDR|xvid|XVID|ape|APE|gif|GIF)' + _filedir '@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|ASF|vob|VOB|bin|BIN|dat|DAT|vcd|VCD|ps|PS|pes|PES|fl[iv]|FL[IV]|fxm|FXM|viv|VIV|rm?(j)|RM?(J)|ra?(m)|RA?(M)|yuv|YUV|mov|MOV|qt|QT|mp[234]|MP[234]|m4[av]|M4[AV]|og[gmavx]|OG[GMAVX]|w?(a)v|W?(A)V|dump|DUMP|mk[av]|MK[AV]|m4a|M4A|aac|AAC|m[24]v|M[24]V|dv|DV|rmvb|RMVB|mid|MID|t[ps]|T[PS]|3g[p2]|3gpp?(2)|mpc|MPC|flac|FLAC|vro|VRO|divx|DIVX|aif?(f)|AIF?(F)|m2ts|M2TS|vdr|VDR|xvid|XVID|ape|APE|gif|GIF|nut|NUT|bik|BIK|webm|WEBM|amr|AMR|awb|AWB)?(.part)' ;; esac diff --git a/contrib/msynctool b/completions/msynctool similarity index 100% rename from contrib/msynctool rename to completions/msynctool diff --git a/contrib/mtx b/completions/mtx similarity index 100% rename from contrib/mtx rename to completions/mtx diff --git a/contrib/munin-node b/completions/munin-node similarity index 100% rename from contrib/munin-node rename to completions/munin-node diff --git a/contrib/mutt b/completions/mutt similarity index 100% rename from contrib/mutt rename to completions/mutt diff --git a/contrib/mysqladmin b/completions/mysqladmin similarity index 100% rename from contrib/mysqladmin rename to completions/mysqladmin diff --git a/contrib/ncftp b/completions/ncftp similarity index 100% rename from contrib/ncftp rename to completions/ncftp diff --git a/contrib/net-tools b/completions/net-tools similarity index 85% rename from contrib/net-tools rename to completions/net-tools index 5b86a64a..e7de2b04 100644 --- a/contrib/net-tools +++ b/completions/net-tools @@ -96,6 +96,32 @@ _route() } && complete -F _route route +have ether-wake && +_ether_wake() +{ + COMPREPLY=() + local cur prev + _get_comp_words_by_ref -n : cur prev + + case $prev in + -i) + _available_interfaces + return 0 + ;; + -p) + return 0 + ;; + esac + + if [[ $cur == -* ]]; then + COMPREPLY=( $( compgen -W '-b -D -i -p -V' -- "$cur" ) ) + return 0 + fi + + _mac_addresses +} && +complete -F _ether_wake ether-wake + # Local variables: # mode: shell-script # sh-basic-offset: 4 diff --git a/contrib/nmap b/completions/nmap similarity index 100% rename from contrib/nmap rename to completions/nmap diff --git a/contrib/ntpdate b/completions/ntpdate similarity index 100% rename from contrib/ntpdate rename to completions/ntpdate diff --git a/contrib/openldap b/completions/openldap similarity index 100% rename from contrib/openldap rename to completions/openldap diff --git a/contrib/openssl b/completions/openssl similarity index 100% rename from contrib/openssl rename to completions/openssl diff --git a/contrib/p4 b/completions/p4 similarity index 84% rename from contrib/p4 rename to completions/p4 index 0795a28e..59b02c1d 100644 --- a/contrib/p4 +++ b/completions/p4 @@ -3,10 +3,10 @@ have p4 && _p4() { - local cur prev preprev p4commands p4filetypes + local cur prev words cword p4commands p4filetypes COMPREPLY=() - _get_comp_words_by_ref cur prev preprev + _get_comp_words_by_ref cur prev words cword # rename isn't really a command p4commands="$( p4 help commands | awk 'NF>3 {print $1}' )" @@ -14,9 +14,9 @@ _p4() uresource uxbinary xbinary xltext xtempobj xtext \ text binary resource" - if [ $COMP_CWORD -eq 1 ]; then + if [ $cword -eq 1 ]; then COMPREPLY=( $( compgen -W "$p4commands" -- "$cur" ) ) - elif [ $COMP_CWORD -eq 2 ]; then + elif [ $cword -eq 2 ]; then case $prev in help) COMPREPLY=( $( compgen -W "simple commands \ @@ -29,10 +29,10 @@ _p4() *) ;; esac - elif [ $COMP_CWORD -gt 2 ]; then + elif [ $cword -gt 2 ]; then case $prev in -t) - case $preprev in + case ${words[$cword-2]} in add|edit|reopen) COMPREPLY=( $( compgen -W "$p4filetypes" -- "$cur") ) ;; diff --git a/completions/perl b/completions/perl new file mode 100644 index 00000000..9a1d84bf --- /dev/null +++ b/completions/perl @@ -0,0 +1,61 @@ +# bash completion for perl + +have perl && +{ +_perlmodules() +{ + COMPREPLY=( $( compgen -P "$prefix" -W "$( perl -e 'sub mods { my ($base,$dir)=@_; return if $base !~ /^\Q$ENV{cur}/; chdir($dir) or return; for (glob(q[*.pm])) {s/\.pm$//; print qq[$base$_\n]}; mods(/^(?:[.\d]+|$Config{archname}-$Config{osname}|auto)$/ ? undef : qq[${base}${_}::],qq[$dir/$_]) for grep {-d} glob(q[*]); } mods(undef,$_) for @INC;' )" -- "$cur" ) ) + __ltrim_colon_completions "$1" +} + +_perl() +{ + local cur prev prefix temp + local optPrefix optSuffix + + COMPREPLY=() + _get_comp_words_by_ref -n : cur prev + prefix="" + + # If option not followed by whitespace, reassign prev and cur + if [[ "$cur" == -?* ]]; then + temp=$cur + prev=${temp:0:2} + cur=${temp:2} + optPrefix=-P$prev + optSuffix=-S/ + prefix=$prev + fi + + # only handle module completion for now + case $prev in + -I|-x) + local IFS=$'\n' + COMPREPLY=( $( compgen -d $optPrefix $optSuffix -- "$cur" ) ) + return 0 + ;; + -m|-M) + _perlmodules "$cur" + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-C -s -T -u -U -W -X -h -v -V -c -w -d \ + -D -p -n -a -F -l -0 -I -m -M -P -S -x -i -e ' -- "$cur" ) ) + else + _filedir + fi +} +complete -F _perl -o nospace -o filenames perl + +complete -C $BASH_COMPLETION_DIR/helpers/perldoc -o nospace -o default perldoc +} + +# Local variables: +# mode: shell-script +# sh-basic-offset: 4 +# sh-indent-comment: t +# indent-tabs-mode: nil +# End: +# ex: ts=4 sw=4 et filetype=sh diff --git a/contrib/pine b/completions/pine similarity index 100% rename from contrib/pine rename to completions/pine diff --git a/contrib/pkg-config b/completions/pkg-config similarity index 100% rename from contrib/pkg-config rename to completions/pkg-config diff --git a/contrib/pkg_install b/completions/pkg_install similarity index 100% rename from contrib/pkg_install rename to completions/pkg_install diff --git a/contrib/pkgtools b/completions/pkgtools similarity index 100% rename from contrib/pkgtools rename to completions/pkgtools diff --git a/contrib/pm-utils b/completions/pm-utils similarity index 100% rename from contrib/pm-utils rename to completions/pm-utils diff --git a/contrib/portupgrade b/completions/portupgrade similarity index 100% rename from contrib/portupgrade rename to completions/portupgrade diff --git a/contrib/postfix b/completions/postfix similarity index 100% rename from contrib/postfix rename to completions/postfix diff --git a/contrib/postgresql b/completions/postgresql similarity index 100% rename from contrib/postgresql rename to completions/postgresql diff --git a/contrib/povray b/completions/povray similarity index 96% rename from contrib/povray rename to completions/povray index cd03b940..7abc497a 100644 --- a/contrib/povray +++ b/completions/povray @@ -7,7 +7,7 @@ _povray() defoext=png # default output extension, if cannot be determined FIXME COMPREPLY=() - _get_comp_words_by_ref povcur prev + _get_comp_words_by_ref -c povcur prev _expand || return 0 @@ -49,7 +49,7 @@ _povray() ;; *) cur="$povcur" - _filedir '?(ini|pov)' + _filedir '@(ini|pov)' return 0 ;; esac diff --git a/contrib/procps b/completions/procps similarity index 100% rename from contrib/procps rename to completions/procps diff --git a/contrib/python b/completions/python similarity index 100% rename from contrib/python rename to completions/python diff --git a/contrib/qdbus b/completions/qdbus similarity index 100% rename from contrib/qdbus rename to completions/qdbus diff --git a/contrib/qemu b/completions/qemu similarity index 100% rename from contrib/qemu rename to completions/qemu diff --git a/contrib/quota-tools b/completions/quota-tools similarity index 100% rename from contrib/quota-tools rename to completions/quota-tools diff --git a/contrib/rcs b/completions/rcs similarity index 100% rename from contrib/rcs rename to completions/rcs diff --git a/contrib/rdesktop b/completions/rdesktop similarity index 100% rename from contrib/rdesktop rename to completions/rdesktop diff --git a/contrib/reportbug b/completions/reportbug similarity index 100% rename from contrib/reportbug rename to completions/reportbug diff --git a/contrib/resolvconf b/completions/resolvconf similarity index 100% rename from contrib/resolvconf rename to completions/resolvconf diff --git a/contrib/rfkill b/completions/rfkill similarity index 100% rename from contrib/rfkill rename to completions/rfkill diff --git a/contrib/ri b/completions/ri similarity index 100% rename from contrib/ri rename to completions/ri diff --git a/contrib/rpcdebug b/completions/rpcdebug similarity index 100% rename from contrib/rpcdebug rename to completions/rpcdebug diff --git a/contrib/rpm b/completions/rpm similarity index 86% rename from contrib/rpm rename to completions/rpm index 20f98522..0dbcd048 100644 --- a/contrib/rpm +++ b/completions/rpm @@ -142,7 +142,7 @@ _rpm() -- "$cur" ) ) return 0 ;; - --define|-D) + --define|-D|--fileid|--hdrid|--pkgid) # argument required but no completions available return 0 ;; @@ -164,7 +164,7 @@ _rpm() --excludepath --ignoresize --oldpackage \ --queryformat --repackage --nosuggests" -- "$cur" ) ) else - _filedir 'rpm' + _filedir '[rs]pm' fi ;; -e|--erase) @@ -180,12 +180,11 @@ _rpm() # options common to all query types opts="$opts --changelog --configfiles --conflicts --docfiles --dump --enhances --filesbypkg --filecaps --fileclass - --filecolor --fileprovide --filerequire --filesbypkg - --info --list --obsoletes --pipe --provides - --queryformat --rcfile --requires --scripts --suggests - --triggeredby --triggers --whatprovides --whatrequires --xml" + --filecolor --fileprovide --filerequire --filesbypkg --info + --list --obsoletes --pipe --provides --queryformat --rcfile + --requires --scripts --suggests --triggers --xml" - if [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then + if [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then # -qf completion if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W "$opts --dbpath --fscontext \ @@ -193,23 +192,26 @@ _rpm() else _filedir fi - elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then + elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then # -qg completion _rpm_groups - elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then + elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then # -qp; uninstalled package completion if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W "$opts --ftpport --ftpproxy \ - --httpport --httpproxy" -- "$cur" ) ) + --httpport --httpproxy --nomanifest" -- "$cur" ) ) else - _filedir 'rpm' + _filedir '[rs]pm' fi else # -q; installed package completion if [[ "$cur" == -* ]]; then - COMPREPLY=( $( compgen -W "$opts --dbpath --fscontext \ - --last --root --state" -- "$cur" ) ) - elif [ "${COMP_LINE#* -*([^ -])a}" == "$COMP_LINE" ]; then + COMPREPLY=( $( compgen -W "$opts --all --file --fileid + --dbpath --fscontext --ftswalk --group --hdrid --last + --package --pkgid --root --specfile --state + --triggeredby --whatprovides --whatrequires" \ + -- "$cur" ) ) + elif [[ $COMP_LINE != *\ -@(*([^ -])a|-all )* ]]; then _rpm_installed_packages "$nodig" "$nosig" fi fi @@ -219,7 +221,7 @@ _rpm() COMPREPLY=( $( compgen -W "$opts --nopgp --nogpg --nomd5" \ -- "$cur" ) ) else - _filedir 'rpm' + _filedir '[rs]pm' fi ;; -[Vy]*|--verify) @@ -229,12 +231,12 @@ _rpm() --nofiles --noscripts --nomd5 --querytags --specfile \ --whatrequires --whatprovides" -- "$cur" ) ) # check whether we're doing file completion - elif [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then + elif [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then _filedir - elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then + elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then _rpm_groups - elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then - _filedir 'rpm' + elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then + _filedir '[rs]pm' else _rpm_installed_packages "$nodig" "$nosig" fi @@ -245,7 +247,7 @@ _rpm() --clean --rmsource --rmspec --test --sign --buildroot \ --target --nobuild --nodeps --nodirtokens" -- "$cur" ) ) elif [[ ${COMP_WORDS[1]} == -b* ]]; then - _filedir 'spec' + _filedir spec else _filedir '@(t?(ar.)@([gx]z|bz?(2))|tar.@(lzma|Z))' fi @@ -255,14 +257,14 @@ _rpm() COMPREPLY=( $( compgen -W "$opts --nodeps --rmsource \ --rmspec --sign --nodirtokens --target" -- "$cur" ) ) else - _filedir '?(no)src.rpm' + _filedir '@(?(no)src.r|s)pm' fi ;; --tarbuild) _filedir '@(t?(ar.)@([gx]z|bz?(2))|tar.@(lzma|Z))' ;; --resign|--addsign) - _filedir 'rpm' + _filedir '[rs]pm' ;; --setperms|--setgids) _rpm_installed_packages "$nodig" "$nosig" @@ -272,13 +274,12 @@ _rpm() COMPREPLY=( $( compgen -W '--clean --rmsource --rmspec' \ -- "$cur" ) ) else - _filedir 'spec' + _filedir spec fi ;; --import|--dbpath|--root) if [[ "$cur" == -* ]]; then - COMPREPLY=( $( compgen -W '--import --dbpath --root' \ - -- "$cur" ) ) + COMPREPLY=( $( compgen -W '--import --dbpath --root' -- "$cur" ) ) else _filedir fi diff --git a/contrib/rpmcheck b/completions/rpmcheck similarity index 100% rename from contrib/rpmcheck rename to completions/rpmcheck diff --git a/contrib/rrdtool b/completions/rrdtool similarity index 100% rename from contrib/rrdtool rename to completions/rrdtool diff --git a/contrib/rsync b/completions/rsync similarity index 100% rename from contrib/rsync rename to completions/rsync diff --git a/contrib/rtcwake b/completions/rtcwake similarity index 100% rename from contrib/rtcwake rename to completions/rtcwake diff --git a/contrib/samba b/completions/samba similarity index 100% rename from contrib/samba rename to completions/samba diff --git a/contrib/sbcl b/completions/sbcl similarity index 100% rename from contrib/sbcl rename to completions/sbcl diff --git a/contrib/screen b/completions/screen similarity index 100% rename from contrib/screen rename to completions/screen diff --git a/contrib/service b/completions/service similarity index 100% rename from contrib/service rename to completions/service diff --git a/completions/sh b/completions/sh new file mode 100644 index 00000000..f33705de --- /dev/null +++ b/completions/sh @@ -0,0 +1,41 @@ +# POSIX sh(1) completion + +have sh && +_sh() +{ + COMPREPLY=() + local cur prev + _get_comp_words_by_ref cur prev + + case $prev in + -c) + return 0 + ;; + -o|+o) + COMPREPLY=( $( compgen -W 'allexport errexit ignoreeof monitor + noclobber noglob noexec nolog notify nounset verbose vi + xtrace' -- "$cur" ) ) + return 0 + ;; + esac + + local opts="-a -b -C -e -f -h -i -m -n -o -u -v -x" + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W "$opts -c -s" -- "$cur" ) ) + return 0 + elif [[ "$cur" == +* ]]; then + COMPREPLY=( $( compgen -W "${opts//-/+}" -- "$cur" ) ) + return 0 + fi + + _filedir sh +} && +complete -F _sh -o filenames sh + +# Local variables: +# mode: shell-script +# sh-basic-offset: 4 +# sh-indent-comment: t +# indent-tabs-mode: nil +# End: +# ex: ts=4 sw=4 et filetype=sh diff --git a/contrib/shadow b/completions/shadow similarity index 100% rename from contrib/shadow rename to completions/shadow diff --git a/contrib/sitecopy b/completions/sitecopy similarity index 100% rename from contrib/sitecopy rename to completions/sitecopy diff --git a/contrib/smartctl b/completions/smartctl similarity index 100% rename from contrib/smartctl rename to completions/smartctl diff --git a/contrib/snownews b/completions/snownews similarity index 100% rename from contrib/snownews rename to completions/snownews diff --git a/contrib/sqlite3 b/completions/sqlite3 similarity index 100% rename from contrib/sqlite3 rename to completions/sqlite3 diff --git a/contrib/ssh b/completions/ssh similarity index 99% rename from contrib/ssh rename to completions/ssh index b4bafdee..2c20c2d3 100644 --- a/contrib/ssh +++ b/completions/ssh @@ -246,13 +246,13 @@ _sftp() shopt -u hostcomplete && complete -F _sftp sftp # things we want to escape in remote scp paths -_scp_path_esc="[][(){}<>\",:;^&\!$=?\`|\\ ']" +_scp_path_esc="[][(){}<>\",:;^&\!$=?\`|\\ \t']" # Complete remote files with ssh. If the first arg is -d, complete on dirs # only. Returns paths escaped with three backslashes. _scp_remote_files() { - local IFS=$'\t\n' + local IFS=$'\n' # remove backslash escape from the first colon cur=${cur/\\:/:} @@ -291,7 +291,7 @@ _scp_remote_files() # an optional prefix to add to returned completions. _scp_local_files() { - local IFS=$'\t\n' + local IFS=$'\n' local dirsonly=false if [ "$1" = -d ]; then diff --git a/contrib/sshfs b/completions/sshfs similarity index 100% rename from contrib/sshfs rename to completions/sshfs diff --git a/contrib/strace b/completions/strace similarity index 100% rename from contrib/strace rename to completions/strace diff --git a/contrib/svk b/completions/svk similarity index 100% rename from contrib/svk rename to completions/svk diff --git a/completions/sysbench b/completions/sysbench new file mode 100644 index 00000000..7781791e --- /dev/null +++ b/completions/sysbench @@ -0,0 +1,175 @@ +# bash completion for sysbench + +# We set -o nospace and turn it off in quite a few place for bash < 4 +# reasons; assuming bash >= 4 we could instead not turn it on +# initially but only in the few cases where it's actually needed. + +have sysbench && +_sysbench() +{ + COMPREPLY=() + local cur prev words split=false + _get_comp_words_by_ref -n = cur prev words + + # long options need the "=" (whitespace split doesn't work), but we split + # internally to make processing easier + _split_longopt && split=true + + case $prev in + --num-threads|--max-requests|--max-time|--thread-stack-size| \ + --help|--version|help|version) + return 0 + ;; + --init-rng|--debug|--validate) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'on off' -- "$cur" ) ) + return 0 + ;; + --test) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'fileio cpu memory threads mutex oltp' \ + -- "$cur" ) ) + return 0 + ;; + --cpu-max-prime) + return 0 + ;; + --file-test-mode) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'seqwr seqrewr seqrd rndrd rndwr rndrw' \ + -- "$cur" ) ) + return 0 + ;; + --file-io-mode) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'sync async fastmmap slowmmap' \ + -- "$cur" ) ) + return 0 + ;; + --file-extra-flags) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'sync dsync direct' -- "$cur" ) ) + return 0 + ;; + --file-fsync-all|--file-fsync-end) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'on off' -- "$cur" ) ) + return 0 + ;; + --file-fsync-mode) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'fsync fdatasync' -- "$cur" ) ) + return 0 + ;; + --memory-scope) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'global local' -- "$cur" ) ) + return 0 + ;; + --memory-hugetlb) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'on off' -- "$cur" ) ) + return 0 + ;; + --memory-oper) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'read write none' -- "$cur" ) ) + return 0 + ;; + --memory-access-mode) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'seq rnd' -- "$cur" ) ) + return 0 + ;; + --oltp-test-mode) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'simple complex nontrx sp' -- "$cur" ) ) + return 0 + ;; + --oltp-read-only|--oltp-skip-trx|--oltp-quto-inc|--mysql-ssl) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'on off' -- "$cur" ) ) + return 0 + ;; + --oltp-nontrx-mode) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'select update_key update_nokey insert + delete' -- "$cur" ) ) + return 0 + ;; + --oltp-dist-type) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'uniform gaussian special' -- "$cur" ) ) + return 0 + ;; + --db-driver) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W "$( $1 --test=oltp help 2>/dev/null | + sed -e '/^.*database drivers:/,/^$/!d' \ + -ne 's/^ *\([^ ]*\) .*/\1/p' )" -- "$cur" ) ) + return 0 + ;; + --db-ps-mode) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'auto disable' -- "$cur" ) ) + return 0 + ;; + --mysql-socket) + compopt +o nospace &>/dev/null + _filedir sock + return 0 + ;; + --mysql-table-engine) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'myisam innodb bdb heap ndbcluster + federated' -- "$cur" ) ) + return 0 + ;; + --mysql-engine-trx) + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W 'yes no auto' -- "$cur" ) ) + return 0 + ;; + --*) + $split && return 0 + ;; + esac + + # find out which test we're running + local i test + for (( i=1 ; $i < ${#words[@]}-1 ; i++ )); do + if [[ ${words[i]} == --test* ]]; then + test=${words[i]#*=} + break + fi + done + + local opts="--num-threads= --max-requests= --max-time= --thread-stack-size= + --init-rng= --debug= --validate= --help --version" + + if [[ $test ]]; then + local help=( $( _parse_help $1 "--test=$test help" ) ) + opts="$opts ${help[@]/%/=} prepare run cleanup help version" + else + opts="$opts --test=" + fi + + if [[ "$cur" == -* || ! $test ]]; then + COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) ) + [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} != *= ]] && \ + compopt +o nospace &>/dev/null + else + compopt +o nospace &>/dev/null + COMPREPLY=( $( compgen -W "prepare run cleanup help version" \ + -- "$cur" ) ) + fi +} && +complete -F _sysbench -o nospace sysbench + +# Local variables: +# mode: shell-script +# sh-basic-offset: 4 +# sh-indent-comment: t +# indent-tabs-mode: nil +# End: +# ex: ts=4 sw=4 et filetype=sh diff --git a/contrib/sysctl b/completions/sysctl similarity index 100% rename from contrib/sysctl rename to completions/sysctl diff --git a/contrib/sysv-rc b/completions/sysv-rc similarity index 100% rename from contrib/sysv-rc rename to completions/sysv-rc diff --git a/contrib/tar b/completions/tar similarity index 61% rename from contrib/tar rename to completions/tar index 400daa62..81ecbce0 100644 --- a/contrib/tar +++ b/completions/tar @@ -14,31 +14,30 @@ _tar() fi case ${COMP_WORDS[1]} in - ?(-)[cr]*f) - _filedir - return 0 - ;; - +([^IZzJjy])f) - ext='t@(ar?(.@(Z|gz|bz?(2)|lz?(ma)|xz))|gz|bz?(2)|lz?(ma)|xz)' - regex='t\(ar\(\.\(Z\|gz\|bz2\?\|lzma\|xz\)\)\?\|gz\|bz2\?\|lzma\|xz\)' - ;; - *[Zz]*f) - ext='t?(ar.)@(gz|Z)' - regex='t\(ar\.\)\?\(gz\|Z\)' - ;; - *[Ijy]*f) - ext='t?(ar.)bz?(2)' - regex='t\(ar\.\)\?bz2\?' - ;; - *[J]*f) - ext='t?(ar.)@(lz?(ma)|xz)' - regex='t\(ar\.\)\?\(lzma\|xz\)\?' - ;; - *) - _filedir - return 0 - ;; - + ?(-)[cr]*f) + _filedir + return 0 + ;; + +([^IZzJjy])f) + ext='t@(ar?(.@(Z|gz|bz?(2)|lz?(ma)|xz))|gz|bz?(2)|lz?(ma)|xz)' + regex='t\(ar\(\.\(Z\|gz\|bz2\?\|lzma\|xz\)\)\?\|gz\|bz2\?\|lzma\|xz\)' + ;; + *[Zz]*f) + ext='t?(ar.)@(gz|Z)' + regex='t\(ar\.\)\?\(gz\|Z\)' + ;; + *[Ijy]*f) + ext='t?(ar.)bz?(2)' + regex='t\(ar\.\)\?bz2\?' + ;; + *[J]*f) + ext='t?(ar.)@(lz?(ma)|xz)' + regex='t\(ar\.\)\?\(lzma\|xz\)\?' + ;; + *) + _filedir + return 0 + ;; esac if [[ "$COMP_LINE" == *$ext' ' ]]; then diff --git a/contrib/tcpdump b/completions/tcpdump similarity index 100% rename from contrib/tcpdump rename to completions/tcpdump diff --git a/contrib/unace b/completions/unace similarity index 94% rename from contrib/unace rename to completions/unace index 5ceb7646..73d635d5 100644 --- a/contrib/unace +++ b/completions/unace @@ -14,7 +14,7 @@ _unace() if [ $COMP_CWORD -eq 1 ]; then COMPREPLY=( $( compgen -W 'e l t v x' -- "$cur" ) ) else - _filedir '@(ace|ACE)' + _filedir ace fi fi } && diff --git a/contrib/unrar b/completions/unrar similarity index 95% rename from contrib/unrar rename to completions/unrar index 3fb24dbb..0f5f7094 100644 --- a/contrib/unrar +++ b/completions/unrar @@ -16,7 +16,7 @@ _unrar() if [ $COMP_CWORD -eq 1 ]; then COMPREPLY=( $( compgen -W 'e l lb lt p t v vb vt x' -- "$cur" ) ) else - _filedir '@(rar|RAR)' + _filedir rar fi fi diff --git a/contrib/update-alternatives b/completions/update-alternatives similarity index 100% rename from contrib/update-alternatives rename to completions/update-alternatives diff --git a/contrib/util-linux b/completions/util-linux similarity index 100% rename from contrib/util-linux rename to completions/util-linux diff --git a/contrib/vncviewer b/completions/vncviewer similarity index 100% rename from contrib/vncviewer rename to completions/vncviewer diff --git a/contrib/vpnc b/completions/vpnc similarity index 100% rename from contrib/vpnc rename to completions/vpnc diff --git a/contrib/wireless-tools b/completions/wireless-tools similarity index 100% rename from contrib/wireless-tools rename to completions/wireless-tools diff --git a/contrib/wodim b/completions/wodim similarity index 100% rename from contrib/wodim rename to completions/wodim diff --git a/contrib/wol b/completions/wol similarity index 100% rename from contrib/wol rename to completions/wol diff --git a/contrib/wtf b/completions/wtf similarity index 100% rename from contrib/wtf rename to completions/wtf diff --git a/contrib/wvdial b/completions/wvdial similarity index 92% rename from contrib/wvdial rename to completions/wvdial index 101112ca..3b135f0a 100644 --- a/contrib/wvdial +++ b/completions/wvdial @@ -3,7 +3,7 @@ have wvdial && _wvdial() { - local cur prev config i IFS=$'\t\n' + local cur prev config i IFS=$'\n' COMPREPLY=() _get_comp_words_by_ref cur prev @@ -23,7 +23,7 @@ _wvdial() ;; *) # start with global and personal config files - config="/etc/wvdial.conf"$'\t'"$HOME/.wvdialrc" + config="/etc/wvdial.conf"$'\n'"$HOME/.wvdialrc" # replace with command line config file if present for (( i=1; i < COMP_CWORD; i++ )); do if [[ "${COMP_WORDS[i]}" == "--config" ]]; then diff --git a/contrib/xhost b/completions/xhost similarity index 100% rename from contrib/xhost rename to completions/xhost diff --git a/contrib/xm b/completions/xm similarity index 100% rename from contrib/xm rename to completions/xm diff --git a/contrib/xmllint b/completions/xmllint similarity index 96% rename from contrib/xmllint rename to completions/xmllint index 82feb4a3..d8b5051c 100644 --- a/contrib/xmllint +++ b/completions/xmllint @@ -42,7 +42,7 @@ _xmllint() return 0 fi - _filedir '@(*ml|htm|svg)' + _filedir '@(*ml|htm|svg|xs[dl]|rng|wsdl)' } && complete -F _xmllint -o filenames xmllint diff --git a/contrib/xmlwf b/completions/xmlwf similarity index 100% rename from contrib/xmlwf rename to completions/xmlwf diff --git a/contrib/xmms b/completions/xmms similarity index 86% rename from contrib/xmms rename to completions/xmms index 42c5402c..91b9ff5c 100644 --- a/contrib/xmms +++ b/completions/xmms @@ -14,7 +14,7 @@ _xmms() --enqueue -m --show-main-window -i --sm-client-id \ -v --version' -- "$cur" ) ) else - _filedir '@(mp[23]|MP[23]|ogg|OGG|wav|WAV|pls|m3u|xm|mod|s[3t]m|it|mtm|ult|flac)' + _filedir '@(mp[23]|ogg|wav|pls|m3u|xm|mod|s[3t]m|it|mtm|ult|flac)' fi diff --git a/completions/xmodmap b/completions/xmodmap new file mode 100644 index 00000000..f4f29150 --- /dev/null +++ b/completions/xmodmap @@ -0,0 +1,32 @@ +# xmodmap(1) completion + +have xmodmap && +_xmodmap() +{ + COMPREPLY=() + local cur prev + _get_comp_words_by_ref cur prev + + case $prev in + -display|-e) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-display -help -grammar -verbose -quiet -n + -e -pm -pk -pke -pp' -- "$cur" ) ) + return 0 + fi + + _filedir +} && +complete -F _xmodmap -o filenames xmodmap + +# Local variables: +# mode: shell-script +# sh-basic-offset: 4 +# sh-indent-comment: t +# indent-tabs-mode: nil +# End: +# ex: ts=4 sw=4 et filetype=sh diff --git a/contrib/xrandr b/completions/xrandr similarity index 100% rename from contrib/xrandr rename to completions/xrandr diff --git a/completions/xrdb b/completions/xrdb new file mode 100644 index 00000000..423c0927 --- /dev/null +++ b/completions/xrdb @@ -0,0 +1,37 @@ +# xrdb(1) completion + +have xrdb && +_xrdb() +{ + COMPREPLY=() + local cur prev + _get_comp_words_by_ref cur prev + + case $prev in + -backup|-display|-help) + return 0 + ;; + -cpp|-edit) + _filedir + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-help -display -all -global -screen -screens + -n -quiet -cpp -nocpp -symbols -query -load -override -merge + -remove -retain -edit -backup' -- "$cur" ) ) + return 0 + fi + + _filedir +} && +complete -F _xrdb -o filenames xrdb + +# Local variables: +# mode: shell-script +# sh-basic-offset: 4 +# sh-indent-comment: t +# indent-tabs-mode: nil +# End: +# ex: ts=4 sw=4 et filetype=sh diff --git a/contrib/xsltproc b/completions/xsltproc similarity index 100% rename from contrib/xsltproc rename to completions/xsltproc diff --git a/contrib/xz b/completions/xz similarity index 99% rename from contrib/xz rename to completions/xz index 46420b01..f947b080 100644 --- a/contrib/xz +++ b/completions/xz @@ -52,7 +52,7 @@ _xz() _expand || return 0 - local IFS=$'\t\n' + local IFS=$'\n' COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \ $( compgen -d -- "$cur" ) ) } && diff --git a/contrib/yp-tools b/completions/yp-tools similarity index 100% rename from contrib/yp-tools rename to completions/yp-tools diff --git a/contrib/yum-arch b/completions/yum-arch similarity index 100% rename from contrib/yum-arch rename to completions/yum-arch diff --git a/configure.ac b/configure.ac index 63f0898a..8cb69952 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,7 @@ AC_PREREQ([2.59]) AC_INIT([bash-completion], [1.99]) AM_INIT_AUTOMAKE([foreign dejagnu dist-bzip2 -Wall -Werror]) -AC_CONFIG_FILES([Makefile test/Makefile]) +AC_SUBST(bashcompdir, $sysconfdir/bash_completion.d) +AC_SUBST(helpersdir, $sysconfdir/bash_completion.d/helpers) +AC_CONFIG_FILES([Makefile completions/Makefile helpers/Makefile test/Makefile]) AC_OUTPUT diff --git a/contrib/ipmitool b/contrib/ipmitool deleted file mode 100644 index fc4ec71c..00000000 --- a/contrib/ipmitool +++ /dev/null @@ -1,38 +0,0 @@ -# bash completion for ipmitool - -have ipmitool && -_ipmitool() -{ - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev - - case $prev in - -I) - COMPREPLY=( $( compgen -W 'open imb lan lanplus free' -- "$cur" ) ) - return 0 - ;; - esac - - - if [[ "$cur" == -* ]]; then - COMPREPLY=( $( compgen -W '-h -V -v -c -d -I -H -p -U -f -S -a \ - -e -C -k -y -K -A -P -E -K -m -b -r -B -T -l -o -O' -- "$cur" ) ) - else - COMPREPLY=( $( compgen -W 'raw i2c spd lan chassis power event \ - mc sdr sensor fru gendev sel pef sol tsol isol user \ - channel session sunoem kontronoem picmg fwum firewall \ - exec set hpm ekanalyzer' -- "$cur" ) ) - fi - -} && -complete -F _ipmitool ipmitool - -# Local variables: -# mode: shell-script -# sh-basic-offset: 4 -# sh-indent-comment: t -# indent-tabs-mode: nil -# End: -# ex: ts=4 sw=4 et filetype=sh diff --git a/contrib/perl b/contrib/perl deleted file mode 100644 index 67996f94..00000000 --- a/contrib/perl +++ /dev/null @@ -1,127 +0,0 @@ -# bash completion for perl - -have perl && -{ -_perlmodules() -{ - COMPREPLY=( $( compgen -P "$prefix" -W "$( perl -e 'sub mods { my ($base,$dir)=@_; return if $base !~ /^\Q$ENV{cur}/; chdir($dir) or return; for (glob(q[*.pm])) {s/\.pm$//; print qq[$base$_\n]}; mods(/^(?:[.\d]+|$Config{archname}-$Config{osname}|auto)$/ ? undef : qq[${base}${_}::],qq[$dir/$_]) for grep {-d} glob(q[*]); } mods(undef,$_) for @INC;' )" -- "$cur" ) ) - __ltrim_colon_completions "$1" -} - -_perl() -{ - local cur prev prefix temp - local optPrefix optSuffix - - COMPREPLY=() - _get_comp_words_by_ref -n : cur prev - prefix="" - - # If option not followed by whitespace, reassign prev and cur - if [[ "$cur" == -?* ]]; then - temp=$cur - prev=${temp:0:2} - cur=${temp:2} - optPrefix=-P$prev - optSuffix=-S/ - prefix=$prev - fi - - # only handle module completion for now - case $prev in - -I|-x) - local IFS=$'\t\n' - COMPREPLY=( $( compgen -d $optPrefix $optSuffix -- "$cur" ) ) - return 0 - ;; - -m|-M) - _perlmodules "$cur" - return 0 - ;; - esac - - if [[ "$cur" == -* ]]; then - COMPREPLY=( $( compgen -W '-C -s -T -u -U -W -X -h -v -V -c -w -d \ - -D -p -n -a -F -l -0 -I -m -M -P -S -x -i -e ' -- "$cur" ) ) - else - _filedir - fi -} -complete -F _perl -o nospace -o filenames perl - -_perldoc() -{ - local cur prev prefix temp - - COMPREPLY=() - _get_comp_words_by_ref -n : cur prev - prefix="" - - # completing an option (may or may not be separated by a space) - if [[ "$cur" == -?* ]]; then - temp=$cur - prev=${temp:0:2} - cur=${temp:2} - prefix=$prev - fi - - # complete builtin perl functions - case $prev in - -f) - COMPREPLY=( $( compgen -W 'chomp chop chr crypt hex index lc \ - lcfirst length oct ord pack q qq reverse rindex sprintf \ - substr tr uc ucfirst y m pos quotemeta s split study qr abs \ - atan2 cos exp hex int log oct rand sin sqrt srand pop push \ - shift splice unshift grep join map qw reverse sort unpack \ - delete each exists keys values binmode close closedir \ - dbmclose dbmopen die eof fileno flock format getc print \ - printf read readdir rewinddir say seek seekdir select syscall \ - sysread sysseek syswrite tell telldir truncate warn write \ - pack read syscall sysread syswrite unpack vec -X chdir chmod \ - chown chroot fcntl glob ioctl link lstat mkdir open opendir \ - readlink rename rmdir stat symlink umask unlink utime caller \ - continue do dump eval exit goto last next redo return \ - sub wantarray break caller import local my our state package \ - use defined formline reset scalar undef \ - alarm exec fork getpgrp getppid getpriority kill pipe qx \ - setpgrp setpriority sleep system times wait waitpid \ - import no package require use bless dbmclose dbmopen package \ - ref tie tied untie use accept bind connect getpeername \ - getsockname getsockopt listen recv send setsockopt shutdown \ - socket socketpair msgctl msgget msgrcv msgsnd semctl semget \ - semop shmctl shmget shmread shmwrite endgrent endhostent \ - endnetent endpwent getgrent getgrgid getgrnam getlogin \ - getpwent getpwnam getpwuid setgrent setpwent endprotoent \ - endservent gethostbyaddr gethostbyname gethostent \ - getnetbyaddr getnetbyname getnetent getprotobyname \ - getprotobynumber getprotoent getservbyname getservbyport \ - getservent sethostent setnetent setprotoent setservent \ - gmtime localtime time times lock' -- "$cur" ) ) - return 0 - ;; - esac - - if [[ "$cur" == -* ]]; then - COMPREPLY=( $( compgen -W '-h -v -t -u -m -l -F -X -f -q' -- "$cur" )) - else - # return available modules (unless it is clearly a file) - if [[ "$cur" != */* ]]; then - _perlmodules "$cur" - COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W \ - '$( PAGER=/bin/cat man perl | \ - sed -ne "/perl.*Perl overview/,/perlwin32/p" | \ - awk "\$NF=2 { print \$1}" | command grep perl )' -- "$cur" ) ) - fi - _filedir '@(pl|PL|pm|PM|pod|POD)' - fi -} -complete -F _perldoc -o bashdefault perldoc -} - -# Local variables: -# mode: shell-script -# sh-basic-offset: 4 -# sh-indent-comment: t -# indent-tabs-mode: nil -# End: -# ex: ts=4 sw=4 et filetype=sh diff --git a/helpers/Makefile.am b/helpers/Makefile.am new file mode 100644 index 00000000..991cfce0 --- /dev/null +++ b/helpers/Makefile.am @@ -0,0 +1,3 @@ +helpers_SCRIPTS = perldoc + +EXTRA_DIST = $(helpers_SCRIPTS) diff --git a/helpers/perldoc b/helpers/perldoc new file mode 100755 index 00000000..a366eed7 --- /dev/null +++ b/helpers/perldoc @@ -0,0 +1,102 @@ +#!/usr/bin/env perl +use strict; +use File::Spec::Functions qw( rel2abs catdir catfile no_upwards ); + +sub uniq { my %seen; grep { not $seen{$_}++ } @_ } + +sub get_command_line { + my $comp = substr $ENV{'COMP_LINE'}, 0, $ENV{'COMP_POINT'}; + return split /[ \t]+/, $comp, -1; # if not good enough, use Text::ParseWords +} + +sub slurp_dir { + opendir my $dir, shift or return; + no_upwards readdir $dir; +} + +sub suggestion_from_name { + my ( $file_rx, $path, $name ) = @_; + return if not $name =~ /$file_rx/; + return $name.'::' if -d catdir $path, $name; + return $1; +} + +sub suggestions_from_path { + my ( $file_rx, $path ) = @_; + map { suggestion_from_name $file_rx, $path, $_ } slurp_dir $path; +} + +sub get_package_suggestions { + my ( $pkg ) = @_; + + my @segment = split /::|:\z/, $pkg, -1; + my $file_rx = qr/\A(${\quotemeta pop @segment}\w*)(?:\.pm|\.pod)?\z/; + + my $home = rel2abs $ENV{'HOME'}; + my $cwd = rel2abs do { require Cwd; Cwd::cwd() }; + + my @suggestion = + map { suggestions_from_path $file_rx, $_ } + uniq map { catdir $_, @segment } + grep { $home ne $_ and $cwd ne $_ } + map { $_, ( catdir $_, 'pod' ) } + map { rel2abs $_ } + @INC; + + # fixups + if ( $pkg eq '' ) { + my $total = @suggestion; + @suggestion = grep { not /^perl/ } @suggestion; + my $num_hidden = $total - @suggestion; + push @suggestion, "perl* ($num_hidden hidden)" if $num_hidden; + } + elsif ( $pkg =~ /(? ) { + next if 1 .. /^=head2 Alphabetical Listing of Perl Functions$/; + ++$nest_level if /^=over/; + --$nest_level if /^=back/; + next if $nest_level; + push @suggestion, /^=item (-?\w+)/; + } + + my $func_rx = qr/\A${\quotemeta $func}/; + + return grep { /$func_rx/ } @suggestion; +} + +sub usage { + die map "\n$_\n", ( + "To use, issue the following command in bash:", + "\tcomplete -C perldoc-complete -o nospace -o default perldoc", + "You probably want to put that line in your ~/.bashrc file.\n", + ); +} + +usage() if not exists $ENV{'COMP_LINE'}; + +my ( $cmd, @arg ) = get_command_line(); +my $word = pop @arg; + +print "$_\n" for ( @arg and @arg[-1] eq '-f' ) + ? get_function_suggestions( $word ) + : get_package_suggestions( $word ); diff --git a/test/completion/badblocks.exp b/test/completion/badblocks.exp new file mode 100644 index 00000000..74bfcd5d --- /dev/null +++ b/test/completion/badblocks.exp @@ -0,0 +1 @@ +assert_source_completions badblocks diff --git a/test/completion/dumpe2fs.exp b/test/completion/dumpe2fs.exp new file mode 100644 index 00000000..22d1523c --- /dev/null +++ b/test/completion/dumpe2fs.exp @@ -0,0 +1 @@ +assert_source_completions dumpe2fs diff --git a/test/completion/e2freefrag.exp b/test/completion/e2freefrag.exp new file mode 100644 index 00000000..713ee236 --- /dev/null +++ b/test/completion/e2freefrag.exp @@ -0,0 +1 @@ +assert_source_completions e2freefrag diff --git a/test/completion/e2label.exp b/test/completion/e2label.exp new file mode 100644 index 00000000..2383c98e --- /dev/null +++ b/test/completion/e2label.exp @@ -0,0 +1 @@ +assert_source_completions e2label diff --git a/test/completion/ether-wake.exp b/test/completion/ether-wake.exp new file mode 100644 index 00000000..602ba271 --- /dev/null +++ b/test/completion/ether-wake.exp @@ -0,0 +1 @@ +assert_source_completions ether-wake diff --git a/test/completion/filefrag.exp b/test/completion/filefrag.exp new file mode 100644 index 00000000..eeb5f8ce --- /dev/null +++ b/test/completion/filefrag.exp @@ -0,0 +1 @@ +assert_source_completions filefrag diff --git a/test/completion/freerdp.exp b/test/completion/freerdp.exp new file mode 100644 index 00000000..5ca649a2 --- /dev/null +++ b/test/completion/freerdp.exp @@ -0,0 +1 @@ +assert_source_completions xfreerdp diff --git a/test/completion/iftop.exp b/test/completion/iftop.exp new file mode 100644 index 00000000..5ec1cb57 --- /dev/null +++ b/test/completion/iftop.exp @@ -0,0 +1 @@ +assert_source_completions iftop diff --git a/test/completion/ipmitool.exp b/test/completion/ipmitool.exp new file mode 100644 index 00000000..a5c72a78 --- /dev/null +++ b/test/completion/ipmitool.exp @@ -0,0 +1 @@ +assert_source_completions ipmitool diff --git a/test/completion/sh.exp b/test/completion/sh.exp new file mode 100644 index 00000000..599f3b29 --- /dev/null +++ b/test/completion/sh.exp @@ -0,0 +1 @@ +assert_source_completions sh diff --git a/test/completion/sysbench.exp b/test/completion/sysbench.exp new file mode 100644 index 00000000..68da0a7a --- /dev/null +++ b/test/completion/sysbench.exp @@ -0,0 +1 @@ +assert_source_completions sysbench diff --git a/test/completion/tune2fs.exp b/test/completion/tune2fs.exp new file mode 100644 index 00000000..db034967 --- /dev/null +++ b/test/completion/tune2fs.exp @@ -0,0 +1 @@ +assert_source_completions tune2fs diff --git a/test/completion/xmodmap.exp b/test/completion/xmodmap.exp new file mode 100644 index 00000000..a80bb027 --- /dev/null +++ b/test/completion/xmodmap.exp @@ -0,0 +1 @@ +assert_source_completions xmodmap diff --git a/test/completion/xrdb.exp b/test/completion/xrdb.exp new file mode 100644 index 00000000..522ac311 --- /dev/null +++ b/test/completion/xrdb.exp @@ -0,0 +1 @@ +assert_source_completions xrdb diff --git a/test/fixtures/_filedir/ext/ii.E1 b/test/fixtures/_filedir/ext/ii.E1 new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/_known_hosts_real/known_hosts b/test/fixtures/_known_hosts_real/known_hosts index bf39e848..f655eaa3 100644 --- a/test/fixtures/_known_hosts_real/known_hosts +++ b/test/fixtures/_known_hosts_real/known_hosts @@ -4,3 +4,10 @@ doo ike ssh-rsa qwerty1234/Qwerty+1234== jub,10.0.0.1 kyl,100.0.0.2 +[10.10.0.3]:10022 +[blah]:1234 +fd00:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:5555 +fe80::123:0xff:dead:beef%eth0 +1111:2222:3333:4444:5555:6666:xxxx:abab +11xx:2222:3333:4444:5555:6666:xxxx:abab +::42 diff --git a/test/fixtures/scp/known_hosts b/test/fixtures/scp/known_hosts index d54a04d0..2dfa4b6f 100644 --- a/test/fixtures/scp/known_hosts +++ b/test/fixtures/scp/known_hosts @@ -2,3 +2,4 @@ |1|def doo ike ssh-rsa qwerty1234/Qwerty+1234== +[blah]:1234 diff --git a/test/fixtures/sftp/known_hosts b/test/fixtures/sftp/known_hosts index d54a04d0..6538eb4b 100644 --- a/test/fixtures/sftp/known_hosts +++ b/test/fixtures/sftp/known_hosts @@ -2,3 +2,4 @@ |1|def doo ike ssh-rsa qwerty1234/Qwerty+1234== +[10.10.10.10]:2222 diff --git a/test/lib/completions/badblocks.exp b/test/lib/completions/badblocks.exp new file mode 100644 index 00000000..d453b5bd --- /dev/null +++ b/test/lib/completions/badblocks.exp @@ -0,0 +1,20 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "badblocks " + + +sync_after_int + + +teardown diff --git a/test/lib/completions/cd.exp b/test/lib/completions/cd.exp index 2101f035..6616cd82 100644 --- a/test/lib/completions/cd.exp +++ b/test/lib/completions/cd.exp @@ -37,11 +37,12 @@ sync_after_int set test "Tab should complete CDPATH" # Set CDPATH +assert_bash_exec "declare -p CDPATH &>/dev/null && OLDCDPATH=\$CDPATH || :" assert_bash_exec "CDPATH=\$PWD"; assert_complete "fixtures/shared/default/foo.d/" "cd fixtures/shared/default/fo" $test sync_after_int # Reset CDPATH -assert_bash_exec "unset CDPATH" +assert_bash_exec "declare -p OLDCDPATH &>/dev/null && CDPATH=\$OLDCDPATH || unset CDPATH && unset OLDCDPATH" teardown diff --git a/test/lib/completions/dumpe2fs.exp b/test/lib/completions/dumpe2fs.exp new file mode 100644 index 00000000..e935c504 --- /dev/null +++ b/test/lib/completions/dumpe2fs.exp @@ -0,0 +1,20 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "dumpe2fs " + + +sync_after_int + + +teardown diff --git a/test/lib/completions/e2freefrag.exp b/test/lib/completions/e2freefrag.exp new file mode 100644 index 00000000..1530c9c9 --- /dev/null +++ b/test/lib/completions/e2freefrag.exp @@ -0,0 +1,20 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "e2freefrag " + + +sync_after_int + + +teardown diff --git a/test/lib/completions/e2label.exp b/test/lib/completions/e2label.exp new file mode 100644 index 00000000..8ae7f443 --- /dev/null +++ b/test/lib/completions/e2label.exp @@ -0,0 +1,20 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "e2label " + + +sync_after_int + + +teardown diff --git a/test/lib/completions/ether-wake.exp b/test/lib/completions/ether-wake.exp new file mode 100644 index 00000000..fe1aa174 --- /dev/null +++ b/test/lib/completions/ether-wake.exp @@ -0,0 +1,20 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "ether-wake " + + +sync_after_int + + +teardown diff --git a/test/lib/completions/filefrag.exp b/test/lib/completions/filefrag.exp new file mode 100644 index 00000000..fa80cd05 --- /dev/null +++ b/test/lib/completions/filefrag.exp @@ -0,0 +1,20 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "filefrag " + + +sync_after_int + + +teardown diff --git a/test/lib/completions/freerdp.exp b/test/lib/completions/freerdp.exp new file mode 100644 index 00000000..be61d459 --- /dev/null +++ b/test/lib/completions/freerdp.exp @@ -0,0 +1,20 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "xfreerdp" + + +sync_after_int + + +teardown diff --git a/test/lib/completions/iftop.exp b/test/lib/completions/iftop.exp new file mode 100644 index 00000000..12941610 --- /dev/null +++ b/test/lib/completions/iftop.exp @@ -0,0 +1,20 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "iftop " + + +sync_after_int + + +teardown diff --git a/test/lib/completions/ipmitool.exp b/test/lib/completions/ipmitool.exp new file mode 100644 index 00000000..aa18e3ff --- /dev/null +++ b/test/lib/completions/ipmitool.exp @@ -0,0 +1,20 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "ipmitool " + + +sync_after_int + + +teardown diff --git a/test/lib/completions/scp.exp b/test/lib/completions/scp.exp index e1f7336e..4ab514d9 100644 --- a/test/lib/completions/scp.exp +++ b/test/lib/completions/scp.exp @@ -52,12 +52,12 @@ set test "Tab should complete known-hosts" # Build string list of expected completions # Get hostnames and give them a colon (:) suffix # Hosts `gee' and `hus' are defined in ./fixtures/scp/config - # Hosts `doo' and `ike' are defined in ./fixtures/scp/known_hosts + # Hosts `blah', `doo' and `ike' are defined in ./fixtures/scp/known_hosts set expected {} foreach host [get_hosts] { lappend expected "$host:" } -lappend expected doo: gee: hus: ike: +lappend expected blah: doo: gee: hus: ike: # Append local filenames lappend expected config known_hosts "spaced\\ \\ conf" set dir fixtures/scp @@ -90,8 +90,8 @@ foreach host [get_hosts] { lappend expected "$host:" } # Hosts `gee', `hus' and `jar' are defined in "./fixtures/scp/spaced conf" - # Hosts `doo' and `ike' are defined in ./fixtures/scp/known_hosts -lappend expected doo: gee: hus: ike: jar: + # Hosts `blah', `doo' and `ike' are defined in ./fixtures/scp/known_hosts +lappend expected blah: doo: gee: hus: ike: jar: # Append local filenames lappend expected config known_hosts "spaced\\ \\ conf" set dir fixtures/scp diff --git a/test/lib/completions/sftp.exp b/test/lib/completions/sftp.exp index 7a197c7c..30837ec6 100644 --- a/test/lib/completions/sftp.exp +++ b/test/lib/completions/sftp.exp @@ -18,9 +18,9 @@ setup # Build string list of expected completions set expected [get_hosts] # Hosts `gee' and `hus' are defined in ./fixtures/sftp/config - # Hosts `doo' and `ike' are defined in ./fixtures/sftp/known_hosts -lappend expected doo gee hus ike -set dir fixtures/scp + # Hosts `10.10.10.10', `doo' and `ike' are defined in ./fixtures/sftp/known_hosts +lappend expected 10.10.10.10 doo gee hus ike +set dir fixtures/sftp assert_complete_dir $expected "sftp -F config " $dir @@ -45,9 +45,9 @@ sync_after_int # Build string list of expected completions # Get hostnames and give them a colon (:) suffix set expected [get_hosts] - # Hosts `gee', `hus' and `jar' are defined in "./fixtures/scp/spaced conf" - # Hosts `doo' and `ike' are defined in ./fixtures/scp/known_hosts -lappend expected doo gee hus ike jar + # Hosts `gee', `hus' and `jar' are defined in "./fixtures/sftp/spaced conf" + # Hosts `10.10.10.10', `doo' and `ike' are defined in ./fixtures/sftp/known_hosts +lappend expected 10.10.10.10 doo gee hus ike jar set dir fixtures/sftp assert_complete_dir $expected "sftp -F spaced\\ \\ conf " $dir diff --git a/test/lib/completions/sh.exp b/test/lib/completions/sh.exp new file mode 100644 index 00000000..e1a51bb9 --- /dev/null +++ b/test/lib/completions/sh.exp @@ -0,0 +1,38 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "sh -" + + +sync_after_int + + +assert_complete_any "sh +" + + +sync_after_int + + +assert_complete_any "sh -o " + + +sync_after_int + + +assert_no_complete "sh -c " + + +sync_after_int + + +teardown diff --git a/test/lib/completions/sudo.exp b/test/lib/completions/sudo.exp index e7a39162..1afd9933 100644 --- a/test/lib/completions/sudo.exp +++ b/test/lib/completions/sudo.exp @@ -17,4 +17,10 @@ assert_complete "fixtures/shared/default/foo.d/" "sudo cd fixtures/shared/defaul sync_after_int +assert_complete "fixtures/" "sudo sh fix" + + +sync_after_int + + teardown diff --git a/test/lib/completions/sysbench.exp b/test/lib/completions/sysbench.exp new file mode 100644 index 00000000..2a0fe339 --- /dev/null +++ b/test/lib/completions/sysbench.exp @@ -0,0 +1,20 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "sysbench " + + +sync_after_int + + +teardown diff --git a/test/lib/completions/tune2fs.exp b/test/lib/completions/tune2fs.exp new file mode 100644 index 00000000..df70d904 --- /dev/null +++ b/test/lib/completions/tune2fs.exp @@ -0,0 +1,20 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "tune2fs " + + +sync_after_int + + +teardown diff --git a/test/lib/completions/xmodmap.exp b/test/lib/completions/xmodmap.exp new file mode 100644 index 00000000..2bf4da1c --- /dev/null +++ b/test/lib/completions/xmodmap.exp @@ -0,0 +1,20 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "xmodmap " + + +sync_after_int + + +teardown diff --git a/test/lib/completions/xrdb.exp b/test/lib/completions/xrdb.exp new file mode 100644 index 00000000..f02625dc --- /dev/null +++ b/test/lib/completions/xrdb.exp @@ -0,0 +1,20 @@ +proc setup {} { + save_env +} + + +proc teardown {} { + assert_env_unmodified +} + + +setup + + +assert_complete_any "xrdb " + + +sync_after_int + + +teardown diff --git a/test/lib/library.exp b/test/lib/library.exp index a79ec526..ffabefcf 100644 --- a/test/lib/library.exp +++ b/test/lib/library.exp @@ -33,6 +33,7 @@ proc assert_bash_exec {{aCmd ""} {title ""} {prompt /@} {out -1}} { ] ] if {$out == -1 && [string length $results] > 0} { + # Is DejaGnu fully initialized, i.e. is "fail" method available? if {[info exists multipass_name]} { fail "ERROR Unexpected output from bash command \"$title\"" } @@ -44,6 +45,7 @@ proc assert_bash_exec {{aCmd ""} {title ""} {prompt /@} {out -1}} { expect { -ex "$cmd\r\n0\r\n$prompt" {} $prompt { + # Is DejaGnu fully initialized, i.e. is "fail" method available? if {[info exists multipass_name]} { fail "ERROR executing bash command \"$title\"" } @@ -698,7 +700,7 @@ proc _save_env {{file ""}} { # Source bash_completion package proc source_bash_completion {} { - assert_bash_exec {BASH_COMPLETION_DIR=$(cd "$TESTDIR/.."; pwd)/contrib} + assert_bash_exec {BASH_COMPLETION_DIR=$(cd "$TESTDIR/.."; pwd)/completions} assert_bash_exec {BASH_COMPLETION_COMPAT_DIR=$BASH_COMPLETION_DIR} assert_bash_exec {BASH_COMPLETION=$(cd "$TESTDIR/.."; pwd)/bash_completion} assert_bash_exec {source "$BASH_COMPLETION"} diff --git a/test/runLint b/test/runLint index b2bf005c..88c717a2 100755 --- a/test/runLint +++ b/test/runLint @@ -3,7 +3,7 @@ gitgrep() { local out=$(git grep -I -E -n "$1" | \ - grep -E '^(bash_completion|contrib/|test/)' | \ + grep -E '^(bash_completion|completions/|test/)' | \ grep -Fv 'test/runLint') if [ -n "$out" ] ; then printf '***** %s\n' "$2" diff --git a/test/unit/_filedir.exp b/test/unit/_filedir.exp index 204d31cf..987df526 100644 --- a/test/unit/_filedir.exp +++ b/test/unit/_filedir.exp @@ -242,7 +242,7 @@ foreach name {f f2} { set test "completing with filter '.e1' should show completions" -assert_complete_dir {ee.e1 foo/ gg.e1} "g " "fixtures/_filedir/ext" $test +assert_complete_dir {ee.e1 foo/ gg.e1 ii.E1} "g " "fixtures/_filedir/ext" $test sync_after_int @@ -251,12 +251,7 @@ sync_after_int set test "completing f aé should return g when LC_CTYPE=C" # Backup/set LC_CTYPE assert_bash_exec {OLD_CTYPE=$LC_CTYPE; LC_CTYPE=C} -if {[lindex $::BASH_VERSINFO 0] > 3} { - assert_complete_dir g "f aé/" "fixtures/_filedir" -} else { - assert_complete_dir "\b\b\b\b$'a\\\\303\\\\251/g'" "f aé/" \ - "fixtures/_filedir" -} +assert_complete_dir g "f aé/" "fixtures/_filedir" # Restore LC_CTYPE assert_bash_exec {[[ $OLD_CTYPE ]] && LC_CTYPE=$OLD_CTYPE || unset LC_CTYPE} diff --git a/test/unit/_get_comp_words_by_ref.exp b/test/unit/_get_comp_words_by_ref.exp index c88ad6f6..cb3f4dad 100644 --- a/test/unit/_get_comp_words_by_ref.exp +++ b/test/unit/_get_comp_words_by_ref.exp @@ -202,6 +202,21 @@ assert_bash_list {"c: b"} $cmd $test sync_after_int +set test {a b:c | with WORDBREAKS -= :}; # | = cursor position +if {[lindex $::BASH_VERSINFO 0] <= 3} { + set cmd {COMP_WORDS=(a b:c ''); COMP_CWORD=2} +} else { + set cmd {COMP_WORDS=(a b : c ''); COMP_CWORD=4} +} +append cmd {; COMP_LINE='a b:c '; COMP_POINT=6} +assert_bash_exec $cmd $test +set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"} +assert_bash_list {" b:c"} $cmd $test + + +sync_after_int + + set test {a :| with WORDBREAKS -= : should return :}; # | = cursor position set cmd {COMP_WORDS=(a :); COMP_CWORD=1; COMP_LINE='a :'; COMP_POINT=3} assert_bash_exec $cmd diff --git a/test/unit/_known_hosts_real.exp b/test/unit/_known_hosts_real.exp index 31842792..c23a9cef 100644 --- a/test/unit/_known_hosts_real.exp +++ b/test/unit/_known_hosts_real.exp @@ -17,8 +17,8 @@ setup set test "Hosts should be put in COMPREPLY" set hosts [get_hosts] # Hosts `gee', `hus' and `jar' are defined in ./fixtures/_known_hosts_real/config - # doo, ike, jub, 10.0.0.1, kyl and 100.0.0.2 in ./fixtures/_known_hosts_real/known_hosts -lappend hosts doo gee hus ike jar jub kyl 10.0.0.1 100.0.0.2 + # doo, ike, jub, 10.0.0.1, kyl, 100.0.0.2, 10.10.0.3, blah, and bunch of IPv6 test cases in ./fixtures/_known_hosts_real/known_hosts +lappend hosts blah doo gee hus ike jar jub kyl 10.0.0.1 100.0.0.2 10.10.0.3 fd00:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:5555 fe80::123:0xff:dead:beef%eth0 1111:2222:3333:4444:5555:6666:xxxx:abab 11xx:2222:3333:4444:5555:6666:xxxx:abab ::42 set cmd {unset COMPREPLY; _known_hosts_real -aF fixtures/_known_hosts_real/config ''; echo_array COMPREPLY} assert_bash_list $hosts $cmd $test @@ -29,8 +29,8 @@ sync_after_int set test "Hosts should have username prefix and colon suffix" set hosts [get_hosts] # Hosts `gee', `hus' and `jar' are defined in ./fixtures/_known_hosts_real/config - # doo, ike jub, 10.0.0.1, kyl and 100.0.0.2 in ./fixtures/_known_hosts_real/known_hosts -lappend hosts doo gee hus ike jar jub kyl 10.0.0.1 100.0.0.2 + # doo, ike, jub, 10.0.0.1, kyl, 100.0.0.2, 10.10.0.3, blah, and bunch of IPv6 test cases in ./fixtures/_known_hosts_real/known_hosts +lappend hosts blah doo gee hus ike jar jub kyl 10.0.0.1 100.0.0.2 10.10.0.3 fd00:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:5555 fe80::123:0xff:dead:beef%eth0 1111:2222:3333:4444:5555:6666:xxxx:abab 11xx:2222:3333:4444:5555:6666:xxxx:abab ::42 set hosts [lsort -ascii $hosts] set expected {} foreach host $hosts { @@ -103,8 +103,8 @@ set test "Empty COMP_KNOWN_HOSTS_WITH_HOSTFILE should omit HOSTFILE" assert_bash_exec "COMP_KNOWN_HOSTS_WITH_HOSTFILE=" set hosts [get_hosts_avahi] # Hosts `gee', `hus' and `jar' are defined in ./fixtures/_known_hosts_real/config - # doo, ike, jub, 10.0.0.1, kyl and 100.0.0.2 in ./fixtures/_known_hosts_real/known_hosts -lappend hosts doo gee hus ike jar jub kyl 10.0.0.1 100.0.0.2 + # doo, ike, jub, 10.0.0.1, kyl, 100.0.0.2, 10.10.0.3, blah, and bunch of IPv6 test cases in ./fixtures/_known_hosts_real/known_hosts +lappend hosts blah doo gee hus ike jar jub kyl 10.0.0.1 100.0.0.2 10.10.0.3 fd00:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:5555 fe80::123:0xff:dead:beef%eth0 1111:2222:3333:4444:5555:6666:xxxx:abab 11xx:2222:3333:4444:5555:6666:xxxx:abab ::42 # Call _known_hosts set cmd {unset COMPREPLY; _known_hosts_real -aF fixtures/_known_hosts_real/config ''; echo_array COMPREPLY} assert_bash_list $hosts $cmd $test diff --git a/test/unit/_parse_help.exp b/test/unit/_parse_help.exp new file mode 100644 index 00000000..4beb28d2 --- /dev/null +++ b/test/unit/_parse_help.exp @@ -0,0 +1,73 @@ +# By Stephen Gildea, October 2010. + +proc setup {} { + save_env +} + +proc teardown {} { + assert_env_unmodified { + /declare -f fn/d + } +} + +setup + + +set cmd {fn() { printf '%s\n' ""; }; _parse_help fn} +assert_bash_list "" $cmd "empty" +sync_after_int + +set cmd {fn() { printf '%s\n' "no dashes here"; }; _parse_help fn} +assert_bash_list "" $cmd "no dashes" +sync_after_int + +set cmd {fn() { printf '%s\n' "internal-dash"; }; _parse_help fn} +assert_bash_list "" $cmd "internal dash 1" +sync_after_int + +set cmd {fn() { printf '%s\n' "no -leading-dashes"; }; _parse_help fn} +assert_bash_list "" $cmd "no leading dash" +sync_after_int + +set cmd {fn() { printf '%s\n' "-one dash"; }; _parse_help fn} +assert_bash_list "-one" $cmd "one dash" +sync_after_int + +set cmd {fn() { printf '%s\n' " -space dash"; }; _parse_help fn} +assert_bash_list "-space" $cmd "one dash after space" +sync_after_int + +set cmd {fn() { printf '%s\n' "-one -two dashes"; }; _parse_help fn} +assert_bash_list "-one\n-two" $cmd "two dashes, space-separated" +sync_after_int + +set cmd {fn() { printf '%s\n' "-one,-t dashes"; }; _parse_help fn} +assert_bash_list "-one\n-t" $cmd "two dashes, comma-separated" +sync_after_int + +set cmd {fn() { printf '%s\n' "-one dash-inside"; }; _parse_help fn} +assert_bash_list "-one" $cmd "internal dash 2" +sync_after_int + +set cmd {fn() { printf '%s\n' "--long-arg=value"; }; _parse_help fn} +assert_bash_list "--long-arg" $cmd "value stripped" +sync_after_int + +set cmd {fn() { printf '%s\n' "--long-arg=-value"; }; _parse_help fn} +assert_bash_list "--long-arg" $cmd "value not seen as option" +sync_after_int + +set cmd {fn() { printf '%s\n' "--long-arg=-value,--opt2=val"; }; _parse_help fn} +assert_bash_list "--long-arg\n--opt2" $cmd "two options with values" +sync_after_int + +set cmd {fn() { printf '%s\n' "-m,--mirror"; }; _parse_help fn} +assert_bash_list "-m\n--mirror" $cmd "short + long" +sync_after_int + +set cmd {fn() { printf '%s\n' "-T/--upload-file"; }; _parse_help fn} +assert_bash_list "-T\n--upload-file" $cmd "short + long, slash separated" +sync_after_int + + +teardown