home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / etc / bash_completion < prev    next >
Encoding:
Text File  |  2007-04-10  |  210.9 KB  |  9,300 lines

  1. #   bash_completion - programmable completion functions for bash 3.x
  2. #              (backwards compatible with bash 2.05b)
  3. #
  4. #   $Id: bash_completion,v 1.872 2006/03/01 16:20:18 ianmacd Exp $
  5. #
  6. #   Copyright (C) Ian Macdonald <ian@caliban.org>
  7. #
  8. #   This program is free software; you can redistribute it and/or modify
  9. #   it under the terms of the GNU General Public License as published by
  10. #   the Free Software Foundation; either version 2, or (at your option)
  11. #   any later version.
  12. #
  13. #   This program is distributed in the hope that it will be useful,
  14. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. #   GNU General Public License for more details.
  17. #
  18. #   You should have received a copy of the GNU General Public License
  19. #   along with this program; if not, write to the Free Software Foundation,
  20. #   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. #
  22. #   The latest version of this software can be obtained here:
  23. #
  24. #   http://www.caliban.org/bash/index.shtml#completion
  25. #
  26. #   RELEASE: 20060301
  27.  
  28. [ -n "${BASH_COMPLETION_DEBUG:-}" ] && set -v || set +v
  29.  
  30. # Alter the following to reflect the location of this file.
  31. #
  32. {
  33.   # These declarations must go within braces in order to be able to silence
  34.   # readonly variable errors.
  35.   BASH_COMPLETION="${BASH_COMPLETION:-/etc/bash_completion}"
  36.   BASH_COMPLETION_DIR="${BASH_COMPLETION_DIR:=/etc/bash_completion.d}"
  37. } 2>/dev/null || :
  38. readonly BASH_COMPLETION BASH_COMPLETION_DIR
  39.  
  40. # Set a couple of useful vars
  41. #
  42. UNAME=$( uname -s )
  43. # strip OS type and version under Cygwin (e.g. CYGWIN_NT-5.1 => Cygwin)
  44. UNAME=${UNAME/CYGWIN_*/Cygwin}
  45. RELEASE=$( uname -r )
  46.  
  47. # features supported by bash 2.05 and higher
  48. if [ ${BASH_VERSINFO[0]} -eq 2 ] && [[ ${BASH_VERSINFO[1]} > 04 ]] ||
  49.    [ ${BASH_VERSINFO[0]} -gt 2 ]; then
  50.     declare -r bash205=$BASH_VERSION 2>/dev/null || :
  51.     default="-o default"
  52.     dirnames="-o dirnames"
  53.     filenames="-o filenames"
  54. fi
  55. # features supported by bash 2.05b and higher
  56. if [ ${BASH_VERSINFO[0]} -eq 2 ] && [[ ${BASH_VERSINFO[1]} = "05b" ]] ||
  57.    [ ${BASH_VERSINFO[0]} -gt 2 ]; then
  58.     declare -r bash205b=$BASH_VERSION 2>/dev/null || :
  59.     nospace="-o nospace"
  60. fi
  61. # features supported by bash 3.0 and higher
  62. if [ ${BASH_VERSINFO[0]} -gt 2 ]; then
  63.     declare -r bash3=$BASH_VERSION 2>/dev/null || :
  64.     bashdefault="-o bashdefault"
  65.     plusdirs="-o plusdirs"
  66. fi
  67.  
  68. # Turn on extended globbing and programmable completion
  69. shopt -s extglob progcomp
  70.  
  71. # A lot of the following one-liners were taken directly from the
  72. # completion examples provided with the bash 2.04 source distribution
  73.  
  74. # Make directory commands see only directories
  75. complete -d pushd
  76.  
  77. # The following section lists completions that are redefined later
  78. # Do NOT break these over multiple lines.
  79. #
  80. # START exclude -- do NOT remove this line
  81. complete -f -X '!*.?(t)bz?(2)' bunzip2 bzcat bzcmp bzdiff bzegrep bzfgrep bzgrep
  82. complete -f -X '!*.@(zip|ZIP|jar|JAR|exe|EXE|pk3|war|wsz|ear|zargo|xpi|sxw|ott)' unzip zipinfo
  83. complete -f -X '*.Z' compress znew
  84. complete -f -X '!*.@(Z|gz|tgz|Gz|dz)' gunzip zcmp zdiff zcat zegrep zfgrep zgrep zless zmore
  85. complete -f -X '!*.Z' uncompress
  86. complete -f -X '!*.@(gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX)' ee display
  87. 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
  88. complete -f -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2|.Z))' gv ggv kghostview
  89. complete -f -X '!*.@(dvi|DVI)?(.@(gz|Z|bz2))' xdvi
  90. complete -f -X '!*.@(dvi|DVI)' dvips dviselect dvitype kdvi dvipdf advi
  91. complete -f -X '!*.@(pdf|PDF)' acroread gpdf xpdf kpdf
  92. complete -f -X '!*.@(@(?(e)ps|?(E)PS)?(.gz|.GZ)|pdf|PDF|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)' evince
  93. complete -f -X '!*.@(?(e)ps|?(E)PS)' ps2pdf
  94. complete -f -X '!*.texi*' makeinfo texi2html
  95. complete -f -X '!*.@(?(la)tex|?(LA)TEX|texi|TEXI|dtx|DTX|ins|INS)' tex latex slitex jadetex pdfjadetex pdftex pdflatex texi2dvi
  96. complete -f -X '!*.@(mp3|MP3)' mpg123 mpg321 madplay
  97. complete -f -X '!*.@(mp?(e)g|MP?(E)G|wma|avi|AVI|asf|vob|VOB|bin|dat|vcd|ps|pes|fli|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp3|MP3|ogg|OGG|ogm|OGM|mp4|MP4|wav|WAV|asx|ASX|mng|MNG|srt)' xine aaxine fbxine kaffeine
  98. complete -f -X '!*.@(avi|asf|wmv)' aviplay
  99. complete -f -X '!*.@(rm?(j)|ra?(m)|smi?(l))' realplay
  100. complete -f -X '!*.@(mpg|mpeg|avi|mov|qt)' xanim
  101. complete -f -X '!*.@(ogg|OGG|m3u|flac|spx)' ogg123
  102. complete -f -X '!*.@(mp3|MP3|ogg|OGG|pls|m3u)' gqmpeg freeamp
  103. complete -f -X '!*.fig' xfig
  104. complete -f -X '!*.@(mid?(i)|MID?(I))' playmidi
  105. complete -f -X '!*.@(mid?(i)|MID?(I)|rmi|RMI|rcp|RCP|[gr]36|[GR]36|g18|G18|mod|MOD|xm|XM|it|IT|x3m|X3M)' timidity
  106. complete -f -X '*.@(o|so|so.!(conf)|a|t@(ar?(.@(Z|gz|bz?(2)))|gz|bz?(2))|rpm|zip|ZIP|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MPG|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)' vi vim gvim rvim view rview rgvim rgview gview
  107. complete -f -X '*.@(o|so|so.!(conf)|a|rpm|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MPG|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)' emacs
  108. complete -f -X '!*.@(exe|EXE|com|COM|scr|SCR|exe.so)' wine
  109. complete -f -X '!*.@(zip|ZIP|z|Z|gz|GZ|tgz|TGZ)' bzme
  110. complete -f -X '!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))' netscape mozilla lynx opera galeon curl dillo elinks amaya
  111. complete -f -X '!*.@(sxw|stw|sxg|sgl|doc|dot|rtf|txt|htm|html|odt|ott|odm)' oowriter
  112. complete -f -X '!*.@(sxi|sti|pps|ppt|pot|odp|otp)' ooimpress
  113. complete -f -X '!*.@(sxc|stc|xls|xlw|xlt|csv|ods|ots)' oocalc
  114. complete -f -X '!*.@(sxd|std|sda|sdd|odg|otg)' oodraw
  115. complete -f -X '!*.@(sxm|smf|mml|odf)' oomath
  116. complete -f -X '!*.odb' oobase
  117. complete -f -X '!*.rpm' rpm2cpio
  118. # FINISH exclude -- do not remove this line
  119.  
  120. # start of section containing compspecs that can be handled within bash
  121.  
  122. # user commands see only users
  123. complete -u su usermod userdel passwd chage write chfn groups slay w
  124.  
  125. # group commands see only groups
  126. [ -n "$bash205" ] && complete -g groupmod groupdel newgrp 2>/dev/null
  127.  
  128. # bg completes with stopped jobs
  129. complete -A stopped -P '%' bg
  130.  
  131. # other job commands
  132. complete -j -P '%' fg jobs disown
  133.  
  134. # readonly and unset complete with shell variables
  135. complete -v readonly unset
  136.  
  137. # set completes with set options
  138. complete -A setopt set
  139.  
  140. # shopt completes with shopt options
  141. complete -A shopt shopt
  142.  
  143. # helptopics
  144. complete -A helptopic help
  145.  
  146. # unalias completes with aliases
  147. complete -a unalias
  148.  
  149. # bind completes with readline bindings (make this more intelligent)
  150. complete -A binding bind
  151.  
  152. # type and which complete on commands
  153. complete -c command type which
  154.  
  155. # builtin completes on builtins
  156. complete -b builtin
  157.  
  158. # start of section containing completion functions called by other functions
  159.  
  160. # This function checks whether we have a given program on the system.
  161. # No need for bulky functions in memory if we don't.
  162. #
  163. have()
  164. {
  165.     unset -v have
  166.     PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type $1 &>/dev/null &&
  167.         have="yes"
  168. }
  169.  
  170. # use GNU sed if we have it, since its extensions are still used in our code
  171. #
  172. [ $UNAME != Linux ] && have gsed && alias sed=gsed
  173.  
  174. # This function checks whether a given readline variable
  175. # is `on'.
  176. #
  177. _rl_enabled() 
  178. {
  179.     [[ "$( bind -v )" = *$1+([[:space:]])on* ]]
  180. }
  181.  
  182.  
  183. # This function performs file and directory completion. It's better than
  184. # simply using 'compgen -f', because it honours spaces in filenames.
  185. # If passed -d, it completes only on directories. If passed anything else,
  186. # it's assumed to be a file glob to complete on.
  187. #
  188. _filedir()
  189. {
  190.     local IFS=$'\t\n' xspec #glob
  191.  
  192.     _expand || return 0
  193.  
  194.     #glob=$(set +o|grep noglob) # save glob setting.
  195.     #set -f         # disable pathname expansion (globbing)
  196.  
  197.     if [ "${1:-}" = -d ]; then
  198.         COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -d -- $cur ) )
  199.         #eval "$glob"    # restore glob setting.
  200.         return 0
  201.     fi
  202.  
  203.     xspec=${1:+"!*.$1"}    # set only if glob passed in as $1
  204.     COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -f -X "$xspec" -- "$cur" ) \
  205.             $( compgen -d -- "$cur" ) )
  206.     #eval "$glob"    # restore glob setting.
  207. }
  208.  
  209. # This function completes on signal names
  210. #
  211. _signals()
  212. {
  213.     local i
  214.  
  215.     # standard signal completion is rather braindead, so we need
  216.     # to hack around to get what we want here, which is to
  217.     # complete on a dash, followed by the signal name minus
  218.     # the SIG prefix
  219.     COMPREPLY=( $( compgen -A signal SIG${cur#-} ))
  220.     for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
  221.         COMPREPLY[i]=-${COMPREPLY[i]#SIG}
  222.     done
  223. }
  224.  
  225. # This function completes on configured network interfaces
  226. #
  227. _configured_interfaces()
  228. {
  229.     if [ -f /etc/debian_version ]; then
  230.         # Debian system
  231.         COMPREPLY=( $( sed -ne 's|^iface \([^ ]\+\).*$|\1|p' \
  232.                    /etc/network/interfaces ) )
  233.     elif [ -f /etc/SuSE-release ]; then
  234.         # SuSE system
  235.         COMPREPLY=( $( command ls \
  236.             /etc/sysconfig/network/ifcfg-* | \
  237.             sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) )
  238.     elif [ -f /etc/pld-release ]; then
  239.         # PLD Linux
  240.         COMPREPLY=( $( command ls -B \
  241.             /etc/sysconfig/interfaces | \
  242.             sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) )
  243.     else
  244.         # Assume Red Hat
  245.         COMPREPLY=( $( command ls \
  246.             /etc/sysconfig/network-scripts/ifcfg-* | \
  247.             sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) )
  248.     fi
  249. }
  250.  
  251. # This function completes on all available network interfaces
  252. # -a: restrict to active interfaces only
  253. # -w: restrict to wireless interfaces only
  254. #
  255. _available_interfaces()
  256. {
  257.     local cmd
  258.  
  259.     if [ "${1:-}" = -w ]; then
  260.         cmd="iwconfig"
  261.     elif [ "${1:-}" = -a ]; then
  262.         cmd="ifconfig"
  263.     else
  264.         cmd="ifconfig -a"
  265.     fi
  266.  
  267.     COMPREPLY=( $( eval $cmd 2>/dev/null | \
  268.         sed -ne 's|^\('$cur'[^[:space:][:punct:]]\{1,\}\).*$|\1|p') )
  269. }
  270.  
  271. # This function expands tildes in pathnames
  272. #
  273. _expand()
  274. {
  275.     [ "$cur" != "${cur%\\}" ] && cur="$cur\\"
  276.  
  277.     # expand ~username type directory specifications
  278.     if [[ "$cur" == \~*/* ]]; then
  279.         eval cur=$cur
  280.         
  281.     elif [[ "$cur" == \~* ]]; then
  282.         cur=${cur#\~}
  283.         COMPREPLY=( $( compgen -P '~' -u $cur ) )
  284.         return ${#COMPREPLY[@]}
  285.     fi
  286. }
  287.  
  288. # This function completes on process IDs.
  289. # AIX and Solaris ps prefers X/Open syntax.
  290. [ $UNAME = SunOS -o $UNAME = AIX ] &&
  291. _pids()
  292. {
  293.     COMPREPLY=( $( compgen -W '$( command ps -efo pid | sed 1d )' -- $cur ))
  294. } ||
  295. _pids()
  296. {
  297.     COMPREPLY=( $( compgen -W '$( command ps axo pid | sed 1d )' -- $cur ) )
  298. }
  299.  
  300. # This function completes on process group IDs.
  301. # AIX and SunOS prefer X/Open, all else should be BSD.
  302. [ $UNAME = SunOS -o $UNAME = AIX ] &&
  303. _pgids()
  304. {
  305.     COMPREPLY=( $( compgen -W '$( command ps -efo pgid | sed 1d )' -- $cur ))
  306. } ||
  307. _pgids()
  308. {
  309.     COMPREPLY=( $( compgen -W '$( command ps axo pgid | sed 1d )' -- $cur ))
  310. }
  311.  
  312. # This function completes on user IDs
  313. #
  314. _uids()
  315. {
  316.     if type getent &>/dev/null; then
  317.         COMPREPLY=( $( getent passwd | \
  318.                 awk -F: '{if ($3 ~ /^'$cur'/) print $3}' ) )
  319.     elif type perl &>/dev/null; then
  320.         COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($uid) = (getpwent)[2]) { print $uid . "\n" }'"'"' )' -- $cur ) )
  321.     else
  322.         # make do with /etc/passwd
  323.         COMPREPLY=( $( awk 'BEGIN {FS=":"} {if ($3 ~ /^'$cur'/) print $3}'\
  324.                 /etc/passwd ) )
  325.     fi
  326. }
  327.  
  328. # This function completes on group IDs
  329. #
  330. _gids()
  331. {
  332.     if type getent &>/dev/null; then
  333.         COMPREPLY=( $( getent group | \
  334.                 awk -F: '{if ($3 ~ /^'$cur'/) print $3}' ) )
  335.     elif type perl &>/dev/null; then
  336.         COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($gid) = (getgrent)[2]) { print $gid . "\n" }'"'"' )' -- $cur ) )
  337.     else
  338.         # make do with /etc/group
  339.         COMPREPLY=( $( awk 'BEGIN {FS=":"} {if ($3 ~ /^'$cur'/) print $3}'\
  340.                 /etc/group ) )
  341.     fi
  342. }
  343.  
  344. # This function completes on services
  345. #
  346. _services()
  347. {
  348.     local sysvdir famdir
  349.     [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d
  350.     famdir=/etc/xinetd.d
  351.     COMPREPLY=( $( builtin echo $sysvdir/!(*.rpmsave|*.rpmorig|*~|functions)) )
  352.  
  353.     if [ -d $famdir ]; then
  354.         COMPREPLY=( ${COMPREPLY[@]} $( builtin echo $famdir/!(*.rpmsave|*.rpmorig|*~)) )
  355.     fi
  356.  
  357.     COMPREPLY=( $( compgen -W '${COMPREPLY[@]#@($sysvdir|$famdir)/}' -- $cur ) )
  358. }
  359.  
  360. # This function complete on modules
  361. #
  362. _modules()
  363. {
  364.     local modpath
  365.     modpath=/lib/modules/$1
  366.     COMPREPLY=( $( command ls -R $modpath | \
  367.             sed -ne 's/^\('$cur'.*\)\.k\?o\(\|.gz\)$/\1/p') )
  368. }
  369.  
  370. # this function complete on user:group format
  371. #
  372. _usergroup()
  373. {
  374.     local IFS=$'\n'
  375.     cur=${cur//\\\\ / }
  376.     if [[ $cur = *@(\\:|.)* ]] && [ -n "$bash205" ]; then
  377.         user=${cur%%*([^:.])}
  378.         COMPREPLY=( $(compgen -P ${user/\\\\} -g -- ${cur##*[.:]}) )
  379.     elif [[ $cur = *:* ]] && [ -n "$bash205" ]; then
  380.         COMPREPLY=( $( compgen -g -- ${cur##*[.:]} ) )
  381.     else
  382.         COMPREPLY=( $( compgen -S : -u -- $cur ) )
  383.     fi
  384. }
  385.  
  386. # this function count the number of mandatory args
  387. #
  388. _count_args()
  389. {
  390.     args=1
  391.     for (( i=1; i < COMP_CWORD; i++ )); do
  392.         if [[ "${COMP_WORDS[i]}" != -* ]]; then
  393.             args=$(($args+1))
  394.         fi
  395.     done
  396. }
  397.  
  398. # start of section containing completion functions for bash built-ins
  399.  
  400. # bash alias completion
  401. #
  402. _alias()
  403. {
  404.     local cur
  405.  
  406.     COMPREPLY=()
  407.     cur=${COMP_WORDS[$COMP_CWORD]}
  408.  
  409.     case "$COMP_LINE" in
  410.     *[^=])
  411.         COMPREPLY=( $( compgen -A alias -S '=' -- $cur ) )
  412.         ;;
  413.     *=)
  414.         COMPREPLY=( "$( alias ${cur%=} 2>/dev/null | \
  415.                  sed -e 's|^alias '$cur'\(.*\)$|\1|' )" )
  416.         ;;
  417.     esac
  418. }
  419. complete -F _alias $nospace alias
  420.  
  421. # bash export completion
  422. #
  423. _export()
  424. {
  425.     local cur
  426.  
  427.     COMPREPLY=()
  428.     cur=${COMP_WORDS[$COMP_CWORD]}
  429.  
  430.     case "$COMP_LINE" in
  431.     *=\$*)
  432.         COMPREPLY=( $( compgen -v -P '$' -- ${cur#*=\$} ) )
  433.         ;;
  434.     *[^=])
  435.         COMPREPLY=( $( compgen -v -S '=' -- $cur ) )
  436.         ;;
  437.     *=)
  438.         COMPREPLY=( "$( eval echo -n \"$`echo ${cur%=}`\" |
  439.             ( echo -n \'
  440.               sed -e 's/'\''/'\''\\\'\'''\''/g'
  441.               echo -n \' ) )" )
  442.         ;;
  443.     esac
  444. }
  445. complete -F _export $default $nospace export
  446.  
  447. # bash shell function completion
  448. #
  449. _function()
  450. {
  451.     local cur prev
  452.  
  453.     COMPREPLY=()
  454.     cur=${COMP_WORDS[COMP_CWORD]}
  455.     prev=${COMP_WORDS[COMP_CWORD-1]}
  456.  
  457.     if [[ $1 == @(declare|typeset) ]]; then
  458.         if [ "$prev" = -f ]; then
  459.             COMPREPLY=( $( compgen -A function -- $cur ) )
  460.         elif [[ "$cur" == -* ]]; then
  461.             COMPREPLY=( $( compgen -W '-a -f -F -i -r -x -p' -- \
  462.                        $cur ) )
  463.         fi
  464.     elif [ $COMP_CWORD -eq 1 ]; then
  465.         COMPREPLY=( $( compgen -A function -- $cur ) )
  466.     else
  467.         COMPREPLY=( "() $( type -- ${COMP_WORDS[1]} | sed -e 1,2d )" )
  468.     fi
  469. }
  470. complete -F _function function declare typeset
  471.  
  472. # bash complete completion
  473. #
  474. _complete()
  475. {
  476.     local cur prev options
  477.  
  478.     COMPREPLY=()
  479.     cur=${COMP_WORDS[COMP_CWORD]}
  480.     prev=${COMP_WORDS[COMP_CWORD-1]}
  481.  
  482.     case $prev in
  483.         -o)
  484.             options="default dirnames filenames"
  485.             [ -n "$bash205b" ] && options="$options nospace"
  486.             [ -n "$bash3" ] && options="$options bashdefault plusdirs"
  487.             COMPREPLY=( $( compgen -W "$options" -- $cur ) )
  488.             return 0
  489.             ;;
  490.  
  491.         -A)
  492.             COMPREPLY=( $( compgen -W 'alias arrayvar binding \
  493.                 builtin command directory disabled enabled \
  494.                 export file function group helptopic hostname \
  495.                 job keyword running service setopt shopt \
  496.                 signal stopped user variable' -- $cur ) )
  497.             return 0
  498.             ;;
  499.  
  500.         -C)
  501.             COMPREPLY=( $( compgen -A command -- $cur ) )
  502.             return 0
  503.             ;;
  504.         -F)
  505.             COMPREPLY=( $( compgen -A function -- $cur ) )
  506.             return 0
  507.             ;;
  508.         -@(p|r))
  509.             COMPREPLY=( $( complete -p | sed -e 's|.* ||' | \
  510.                     grep "^$cur" ) )
  511.             return 0
  512.             ;;
  513.  
  514.     esac
  515.  
  516.     if [[ "$cur" == -* ]]; then
  517.         # relevant options completion
  518.         options="-a -b -c -d -e -f -g -j -k -s -v -u -A -G -W -P -S -X -F -C"
  519.         [ -n "$bash205" ] && options="$options -o"
  520.         COMPREPLY=( $( compgen -W "$options" -- $cur ) )
  521.     else
  522.         COMPREPLY=( $( compgen -A command -- $cur ) )
  523.     fi
  524. }
  525. complete -F _complete complete
  526.  
  527. # start of section containing completion functions for external programs
  528.  
  529. # a little help for FreeBSD ports users
  530. [ $UNAME = FreeBSD ] && complete -W 'index search fetch fetch-list \
  531.     extract patch configure build install reinstall \
  532.     deinstall clean clean-depends kernel buildworld' make
  533.  
  534. # This completes on a list of all available service scripts for the
  535. # 'service' command and/or the SysV init.d directory, followed by
  536. # that script's available commands
  537. #
  538. { have service || [ -d /etc/init.d/ ]; } &&
  539. _service()
  540. {
  541.     local cur sysvdir
  542.  
  543.     COMPREPLY=()
  544.     prev=${COMP_WORDS[COMP_CWORD-1]}
  545.     cur=${COMP_WORDS[COMP_CWORD]}
  546.  
  547.     # don't complete for things like killall, ssh and mysql if it's
  548.     # the standalone command, rather than the init script
  549.     [[ ${COMP_WORDS[0]} != @(*init.d/!(functions|~)|service) ]] && return 0
  550.  
  551.     # don't complete past 2nd token
  552.     [ $COMP_CWORD -gt 2 ] && return 0
  553.  
  554.     [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
  555.                 || sysvdir=/etc/init.d
  556.  
  557.     if [[ $COMP_CWORD -eq 1 ]] && [[ $prev == "service" ]]; then
  558.         _services
  559.     else
  560.         COMPREPLY=( $( compgen -W '`sed -ne "y/|/ /; \
  561.                 s/^.*Usage.*{\(.*\)}.*$/\1/p" \
  562.                 $sysvdir/${prev##*/} 2>/dev/null`' -- $cur ) )
  563.     fi
  564.  
  565.     return 0
  566. } &&
  567. complete -F _service service
  568. [ -d /etc/init.d/ ] && complete -F _service $default \
  569.     $(for i in /etc/init.d/*; do echo ${i##*/}; done)
  570.  
  571. # chown(1) completion
  572. #
  573. _chown()
  574. {
  575.     local cur
  576.     cur=${COMP_WORDS[COMP_CWORD]}
  577.  
  578.     # options completion
  579.     if [[ "$cur" == -* ]]; then
  580.         COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes \
  581.         --dereference --no-dereference --from= --silent --quiet \
  582.         --reference= --recursive --verbose --help --version' -- $cur ) )
  583.     else
  584.         _count_args
  585.  
  586.         case $args in
  587.             1)
  588.                 _usergroup
  589.                 ;;
  590.             *)
  591.                 _filedir
  592.                 ;;
  593.         esac
  594.     fi
  595. }
  596. complete -F _chown $filenames chown
  597.  
  598. # chgrp(1) completion
  599. #
  600. _chgrp()
  601. {
  602.     local cur prev
  603.  
  604.     COMPREPLY=()
  605.     cur=${COMP_WORDS[COMP_CWORD]}
  606.     cur=${cur//\\\\/}
  607.     prev=${COMP_WORDS[COMP_CWORD-1]}
  608.  
  609.     # options completion
  610.     if [[ "$cur" == -* ]]; then
  611.         COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes \
  612.         --dereference --no-dereference --silent --quiet \
  613.         --reference= --recursive --verbose --help --version' -- $cur ) )
  614.         return 0
  615.     fi
  616.  
  617.     # first parameter on line or first since an option?
  618.     if [ $COMP_CWORD -eq 1 ] && [[ "$cur" != -* ]] || \
  619.        [[ "$prev" == -* ]] && [ -n "$bash205" ]; then
  620.         local IFS=$'\n'
  621.         COMPREPLY=( $( compgen -g $cur 2>/dev/null ) )
  622.     else
  623.         _filedir || return 0
  624.     fi
  625.  
  626.     return 0
  627. }
  628. complete -F _chgrp $filenames chgrp
  629.  
  630. # umount(8) completion. This relies on the mount point being the third
  631. # space-delimited field in the output of mount(8)
  632. #
  633. _umount()
  634. {
  635.     local cur
  636.  
  637.     COMPREPLY=()
  638.     cur=${COMP_WORDS[COMP_CWORD]}
  639.  
  640.     COMPREPLY=( $( compgen -W '$( mount | cut -d" " -f 3 )' -- $cur ) )
  641.  
  642.     return 0
  643. }
  644. complete -F _umount $dirnames umount
  645.  
  646. # mount(8) completion. This will pull a list of possible mounts out of
  647. # /etc/{,v}fstab, unless the word being completed contains a ':', which
  648. # would indicate the specification of an NFS server. In that case, we
  649. # query the server for a list of all available exports and complete on
  650. # that instead.
  651. #
  652. _mount()
  653. {       local cur i sm host
  654.  
  655.     COMPREPLY=()
  656.     cur=${COMP_WORDS[COMP_CWORD]}
  657.     [[ "$cur" == \\ ]] && cur="/"
  658.  
  659.     for i in {,/usr}/{,s}bin/showmount; do [ -x $i ] && sm=$i && break; done
  660.  
  661.     if [ -n "$sm" ] && [[ "$cur" == *:* ]]; then
  662.         COMPREPLY=( $( $sm -e ${cur%%:*} | sed 1d | \
  663.                    grep ^${cur#*:} | awk '{print $1}' ) )
  664.     elif [[ "$cur" == //* ]]; then
  665.         host=${cur#//}
  666.         host=${host%%/*}
  667.         if [ -n "$host" ]; then
  668.             COMPREPLY=( $( compgen -W "$( echo $( smbclient -d 0 -NL $host 2>/dev/null|
  669.             sed -ne '/^['"$'\t '"']*Sharename/,/^$/p' |
  670.             sed -ne '3,$s|^[^A-Za-z]*\([^'"$'\t '"']*\).*$|//'$host'/\1|p' ) )" -- "$cur" ) )
  671.         fi
  672.     elif [ -r /etc/vfstab ]; then
  673.         # Solaris
  674.         COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' \
  675.                 /etc/vfstab | grep "^$cur" ) )
  676.     elif [ ! -e /etc/fstab ]; then
  677.         # probably Cygwin
  678.         COMPREPLY=( $( mount | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' \
  679.                  | grep "^$cur" ) )
  680.     else
  681.         # probably Linux
  682.         COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' \
  683.                 /etc/fstab | grep "^$cur" ) )
  684.     fi
  685.  
  686.     return 0
  687. }
  688. complete -F _mount $default $filenames mount
  689.  
  690. # Linux rmmod(8) completion. This completes on a list of all currently
  691. # installed kernel modules.
  692. #
  693. have rmmod && {
  694. _rmmod()
  695. {
  696.     local cur
  697.  
  698.     COMPREPLY=()
  699.     cur=${COMP_WORDS[COMP_CWORD]}
  700.  
  701.     COMPREPLY=( $( /sbin/lsmod | \
  702.           awk '{if (NR != 1 && $1 ~ /^'$cur'/) print $1}' 2>/dev/null ))
  703.     return 0
  704. }
  705. complete -F _rmmod rmmod
  706.  
  707. # Linux insmod(8), modprobe(8) and modinfo(8) completion. This completes on a
  708. # list of all available modules for the version of the kernel currently
  709. # running.
  710. #
  711. _insmod()
  712. {
  713.     local cur prev modpath
  714.  
  715.     COMPREPLY=()
  716.     cur=${COMP_WORDS[COMP_CWORD]}
  717.     prev=${COMP_WORDS[COMP_CWORD-1]}
  718.  
  719.     # behave like lsmod for modprobe -r
  720.     if [ $1 = "modprobe" ] &&
  721.        [ "${COMP_WORDS[1]}" = "-r" ]; then
  722.         COMPREPLY=( $( /sbin/lsmod | \
  723.                 awk '{if (NR != 1 && $1 ~ /^'$cur'/) print $1}' ) )
  724.         return 0
  725.     fi
  726.  
  727.     # do filename completion if we're giving a path to a module
  728.     if [[ "$cur" == */* ]]; then
  729.         _filedir '@(?(k)o?(.gz))'
  730.         return 0
  731.     fi
  732.  
  733.     if [ $COMP_CWORD -gt 1 ] && 
  734.        [[ "${COMP_WORDS[COMP_CWORD-1]}" != -* ]]; then
  735.         # do module parameter completion
  736.         COMPREPLY=( $( /sbin/modinfo -p ${COMP_WORDS[1]} 2>/dev/null | \
  737.                awk '{if ($1 ~ /^parm:/ && $2 ~ /^'$cur'/) { print $2 } \
  738.             else if ($1 !~ /:/ && $1 ~ /^'$cur'/) { print $1 }}' ) )
  739.     else
  740.         _modules $(uname -r)
  741.     fi
  742.  
  743.     return 0
  744. }
  745. complete -F _insmod $filenames insmod modprobe modinfo
  746. }
  747.  
  748. # man(1) completion
  749. #
  750. [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \
  751.   -o $UNAME = FreeBSD -o $UNAME = SunOS -o $UNAME = Cygwin \
  752.   -o $UNAME = OpenBSD ] &&
  753. _man()
  754. {
  755.     local cur prev sect manpath UNAME
  756.  
  757.     COMPREPLY=()
  758.     cur=${COMP_WORDS[COMP_CWORD]}
  759.     prev=${COMP_WORDS[COMP_CWORD-1]}
  760.  
  761.     _expand || return 0
  762.  
  763.     # default completion if parameter contains /
  764.     if [[ "$cur" == */* ]]; then
  765.         _filedir
  766.         return 0
  767.     fi
  768.  
  769.     UNAME=$( uname -s )
  770.     # strip OS type and version under Cygwin
  771.     UNAME=${UNAME/CYGWIN_*/Cygwin}
  772.     if [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = FreeBSD \
  773.          -o $UNAME = Cygwin ]; then
  774.         manpath=$( manpath 2>/dev/null || command man --path )
  775.     else
  776.         manpath=$MANPATH
  777.     fi
  778.  
  779.     if [ -z "$manpath" ]; then
  780.         COMPREPLY=( $( compgen -c -- $cur ) )
  781.         return 0
  782.     fi
  783.  
  784.     # determine manual section to search
  785.     [[ "$prev" == [0-9ln] ]] && sect=$prev || sect='*'
  786.  
  787.     manpath=$manpath:
  788.     if [ -n "$cur" ]; then
  789.         manpath="${manpath//://*man$sect/$cur* } ${manpath//://*cat$sect/$cur* }"
  790.     else
  791.         manpath="${manpath//://*man$sect/ } ${manpath//://*cat$sect/ }"
  792.     fi
  793.         
  794.     # redirect stderr for when path doesn't exist
  795.     COMPREPLY=( $( eval command ls "$manpath" 2>/dev/null ) )
  796.     # weed out directory path names and paths to man pages
  797.     COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
  798.     # strip suffix from man pages
  799.     COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} )
  800.     COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) )
  801.  
  802.     [[ "$prev" != [0-9ln] ]] && _filedir '[0-9ln]'
  803.  
  804.     return 0
  805. }
  806. [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \
  807.   -o $UNAME = FreeBSD -o $UNAME = SunOS -o $UNAME = Cygwin \
  808.   -o $UNAME = OpenBSD ] && \
  809. complete -F _man $filenames man apropos whatis
  810.  
  811. # renice(8) completion
  812. #
  813. _renice()
  814. {
  815.     local command cur curopt i
  816.  
  817.     COMPREPLY=()
  818.     cur=${COMP_WORDS[COMP_CWORD]}
  819.     command=$1
  820.  
  821.     i=0
  822.     # walk back through command line and find last option
  823.     while [ $i -le $COMP_CWORD -a ${#COMPREPLY[@]} -eq 0 ]; do
  824.         curopt=${COMP_WORDS[COMP_CWORD-$i]}
  825.         case "$curopt" in
  826.         -u)
  827.             COMPREPLY=( $( compgen -u -- $cur ) )
  828.             ;;
  829.         -g)
  830.             _pgids
  831.             ;;
  832.         -p|$command)
  833.             _pids
  834.             ;;
  835.         esac
  836.         i=$(( ++i ))
  837.     done
  838. }
  839. complete -F _renice renice
  840.  
  841. # kill(1) completion
  842. #
  843. _kill()
  844. {
  845.     local cur
  846.  
  847.     COMPREPLY=()
  848.     cur=${COMP_WORDS[COMP_CWORD]}
  849.  
  850.     if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then
  851.         # return list of available signals
  852.         _signals
  853.     else
  854.         # return list of available PIDs
  855.         _pids
  856.     fi
  857. }
  858. complete -F _kill kill
  859.  
  860. # Linux and FreeBSD killall(1) completion.
  861. #
  862. [ $UNAME = Linux -o $UNAME = FreeBSD ] &&
  863. _killall()
  864. {
  865.     local cur
  866.  
  867.     COMPREPLY=()
  868.     cur=${COMP_WORDS[COMP_CWORD]}
  869.  
  870.     if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then
  871.         _signals
  872.     else
  873.         COMPREPLY=( $( compgen -W '$( command ps axo command | \
  874.                   sed -ne "1d; s/^\[\?\([^-][^] ]*\).*$/\1/p" | \
  875.                   sed -e "s/.*\///" )' -- $cur ) )
  876.     fi
  877.  
  878.     return 0
  879. }
  880. [ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _killall killall pkill
  881.  
  882. # Linux and FreeBSD pgrep(1) completion.
  883. #
  884. [ $UNAME = Linux -o $UNAME = FreeBSD ] &&
  885. _pgrep()
  886. {
  887.     local cur
  888.  
  889.     COMPREPLY=()
  890.     cur=${COMP_WORDS[COMP_CWORD]}
  891.  
  892.     COMPREPLY=( $( compgen -W '$( command ps axo command | \
  893.               sed -ne "1d; s/^\[\?\([^-][^] ]*\).*$/\1/p" | \
  894.               sed -e "s/.*\///" )' -- $cur ) )
  895.  
  896.     return 0
  897. }
  898. [ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _pgrep pgrep
  899. # Linux pidof(8) completion.
  900. [ $UNAME = Linux ] && complete -F _pgrep pidof
  901.  
  902. # GNU find(1) completion. This makes heavy use of ksh style extended
  903. # globs and contains Linux specific code for completing the parameter
  904. # to the -fstype option.
  905. #
  906. _find()
  907. {
  908.     local cur prev i exprfound onlyonce
  909.  
  910.     COMPREPLY=()
  911.     cur=${COMP_WORDS[COMP_CWORD]}
  912.     prev=${COMP_WORDS[COMP_CWORD-1]}
  913.  
  914.     case "$prev" in
  915.     -@(max|min)depth)
  916.         COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9' -- $cur ) )
  917.         return 0
  918.         ;;
  919.     -?(a|c)newer|-fls|-fprint?(0|f)|-?(i)?(l)name)
  920.         _filedir
  921.         return 0
  922.         ;;
  923.     -fstype)
  924.         # this is highly non-portable
  925.         [ -e /proc/filesystems ] &&
  926.         COMPREPLY=( $( cut -d$'\t' -f 2 /proc/filesystems | \
  927.                 grep "^$cur" ) )
  928.         return 0
  929.         ;;
  930.     -gid)
  931.         _gids
  932.         return 0
  933.         ;;
  934.     -group)
  935.         if [ -n "$bash205" ]; then
  936.             COMPREPLY=( $( compgen -g -- $cur 2>/dev/null) )
  937.         fi
  938.         return 0
  939.         ;;
  940.     -?(x)type)
  941.         COMPREPLY=( $( compgen -W 'b c d p f l s' -- $cur ) )
  942.         return 0
  943.         ;;
  944.     -uid)
  945.         _uids
  946.         return 0
  947.         ;;
  948.     -user)
  949.         COMPREPLY=( $( compgen -u -- $cur ) )
  950.         return 0
  951.         ;;
  952.     -exec|-ok)
  953.         COMP_WORDS=(COMP_WORDS[0] $cur)
  954.         COMP_CWORD=1
  955.         _command
  956.         return 0
  957.         ;;
  958.     -[acm]min|-[acm]time|-?(i)?(l)name|-inum|-?(i)path|-?(i)regex| \
  959.     -links|-perm|-size|-used|-printf)
  960.         # do nothing, just wait for a parameter to be given
  961.         return 0
  962.         ;;
  963.     esac
  964.  
  965.     _expand || return 0
  966.  
  967.     # set exprfound to 1 if there is already an expression present
  968.     for i in ${COMP_WORDS[@]}; do
  969.         [[ "$i" = [-\(\),\!]* ]] && exprfound=1 && break
  970.     done
  971.  
  972.     # handle case where first parameter is not a dash option
  973.     if [ "$exprfound" != 1 ] && [[ "$cur" != [-\(\),\!]* ]]; then
  974.         _filedir -d
  975.         return 0
  976.     fi
  977.  
  978.     # complete using basic options
  979.     COMPREPLY=( $( compgen -W '-daystart -depth -follow -help -maxdepth \
  980.             -mindepth -mount -noleaf -version -xdev -amin -anewer \
  981.             -atime -cmin -cnewer -ctime -empty -false -fstype \
  982.             -gid -group -ilname -iname -inum -ipath -iregex \
  983.             -links -lname -mmin -mtime -name -newer -nouser \
  984.             -nogroup -perm -regex -size -true -type -uid -used \
  985.             -user -xtype -exec -fls -fprint -fprint0 -fprintf -ok \
  986.             -print -print0 -printf -prune -ls' -- $cur ) )
  987.  
  988.     # this removes any options from the list of completions that have
  989.     # already been specified somewhere on the command line, as long as
  990.     # these options can only be used once (in a word, "options", in
  991.     # opposition to "tests" and "actions", as in the find(1) manpage).
  992.     onlyonce=' -daystart -depth -follow -help -maxdepth -mindepth -mount \
  993.            -noleaf -version -xdev '
  994.     COMPREPLY=( $( echo "${COMP_WORDS[@]}" | \
  995.                (while read -d ' ' i; do
  996.                 [ "$i" == "" ] ||
  997.                 [ "${onlyonce/ ${i%% *} / }" == "$onlyonce" ] &&
  998.                 continue
  999.                 # flatten array with spaces on either side,
  1000.                 # otherwise we cannot grep on word boundaries of
  1001.                 # first and last word
  1002.                 COMPREPLY=" ${COMPREPLY[@]} "
  1003.                 # remove word from list of completions
  1004.                 COMPREPLY=( ${COMPREPLY/ ${i%% *} / } )
  1005.             done
  1006.             echo ${COMPREPLY[@]})
  1007.           ) )
  1008.     
  1009.     _filedir
  1010.     
  1011.     return 0
  1012. }
  1013. complete -F _find $filenames find
  1014.  
  1015. # Linux iwconfig(8) completion
  1016. #
  1017. [ $UNAME = Linux ] && have iwconfig &&
  1018. _iwconfig()
  1019. {
  1020.     local cur prev
  1021.  
  1022.     COMPREPLY=()
  1023.     cur=${COMP_WORDS[COMP_CWORD]}
  1024.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1025.     
  1026.     case $prev in
  1027.         mode)
  1028.             COMPREPLY=( $( compgen -W 'managed ad-hoc master \
  1029.                 repeater secondary monitor' -- $cur ) )
  1030.             return 0
  1031.             ;;
  1032.         essid)
  1033.             COMPREPLY=( $( compgen -W 'on off any' -- $cur ) )
  1034.             if [ -n "${COMP_IWLIST_SCAN:-}" ]; then
  1035.                 COMPREPLY=( ${COMPREPLY[@]:-} \
  1036.                     $( iwlist ${COMP_WORDS[1]} scan | \
  1037.                     awk -F '"' '/ESSID/ {print $2}' | \
  1038.                     grep "^$cur" ))
  1039.             fi
  1040.             return 0
  1041.             ;;
  1042.         nwid)
  1043.             COMPREPLY=( $( compgen -W 'on off' -- $cur ) )
  1044.             return 0
  1045.             ;;
  1046.         channel)
  1047.             COMPREPLY=( $( iwlist ${COMP_WORDS[1]} channel | \
  1048.                 awk '/^[[:space:]]*Channel/ {print $2}' | \
  1049.                 grep "^$cur" ) )
  1050.             return 0
  1051.             ;;
  1052.  
  1053.         freq)
  1054.             COMPREPLY=( $( iwlist ${COMP_WORDS[1]} channel | \
  1055.                 awk '/^[[:space:]]*Channel/ {print $4"G"}' | \
  1056.                 grep "^$cur" ) )
  1057.             return 0
  1058.             ;;
  1059.         ap)
  1060.             COMPREPLY=( $( compgen -W 'on off any' -- $cur ) )
  1061.             if [ -n "${COMP_IWLIST_SCAN:-}" ]; then
  1062.                 COMPREPLY=( ${COMPREPLY[@]:-} \
  1063.                     $( iwlist ${COMP_WORDS[1]} scan | \
  1064.                     awk -F ': ' '/Address/ {print $2}' | \
  1065.                     grep "^$cur" ) )
  1066.             fi
  1067.             return 0
  1068.             ;;
  1069.         rate)
  1070.             COMPREPLY=( $( compgen -W 'auto fixed' -- $cur ) )
  1071.             COMPREPLY=( ${COMPREPLY[@]:-} \
  1072.                 $( iwlist ${COMP_WORDS[1]} rate | \
  1073.                 awk '/^[[:space:]]*[0-9]/ {print $1"M"}' | \
  1074.                 grep "^$cur" ) )
  1075.             return 0
  1076.             ;;
  1077.         rts)
  1078.             COMPREPLY=( $( compgen -W 'auto fixed off' -- $cur ) )
  1079.             return 0
  1080.             ;;
  1081.         frag)
  1082.             COMPREPLY=( $( compgen -W 'auto fixed off' -- $cur ) )
  1083.             return 0
  1084.             ;;
  1085.         key)
  1086.             COMPREPLY=( $( compgen -W 'off on open restricted' -- $cur ) )
  1087.             return 0
  1088.             ;;
  1089.         enc)
  1090.             COMPREPLY=( $( compgen -W 'off on open restricted' -- $cur ) )
  1091.             return 0
  1092.             ;;
  1093.         power)
  1094.             COMPREPLY=( $( compgen -W 'period timeout off on' -- $cur ) )
  1095.             return 0
  1096.             ;;
  1097.         txpower)
  1098.             COMPREPLY=( $( compgen -W 'off on auto' -- $cur ) )
  1099.             return 0
  1100.             ;;
  1101.         retry)
  1102.             COMPREPLY=( $( compgen -W 'limit lifetime' -- $cur ) )
  1103.             return 0
  1104.             ;;
  1105.     esac
  1106.  
  1107.     if [ $COMP_CWORD -eq 1 ]; then
  1108.         if [[ "$cur" == -* ]]; then
  1109.             COMPREPLY=( $( compgen -W '--help --version' -- $cur ) ) 
  1110.         else
  1111.             _available_interfaces -w
  1112.         fi
  1113.     else
  1114.         COMPREPLY=( $( compgen -W 'essid nwid mode freq channel sens mode \
  1115.             ap nick rate rts frag enc key power txpower commit' -- $cur ) ) 
  1116.     fi
  1117.  
  1118. } &&
  1119. complete -F _iwconfig iwconfig
  1120.  
  1121. # Linux iwlist(8) completion
  1122. #
  1123. [ $UNAME = Linux ] && have iwlist &&
  1124. _iwlist()
  1125. {
  1126.     local cur prev
  1127.  
  1128.     COMPREPLY=()
  1129.     cur=${COMP_WORDS[COMP_CWORD]}
  1130.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1131.     
  1132.     if [ $COMP_CWORD -eq 1 ]; then
  1133.         if [[ "$cur" == -* ]]; then
  1134.             COMPREPLY=( $( compgen -W '--help --version' -- $cur ) ) 
  1135.         else
  1136.             _available_interfaces -w
  1137.         fi
  1138.     else
  1139.         COMPREPLY=( $( compgen -W 'scan scanning freq frequency \
  1140.             channel rate bit bitrate key enc encryption power \
  1141.             txpower retry ap accesspoint peers event' -- $cur ) ) 
  1142.     fi
  1143. } &&
  1144. complete -F _iwlist iwlist
  1145.  
  1146. # Linux iwspy(8) completion
  1147. #
  1148. [ $UNAME = Linux ] && have iwspy &&
  1149. _iwspy()
  1150. {
  1151.     local cur
  1152.  
  1153.     COMPREPLY=()
  1154.     cur=${COMP_WORDS[COMP_CWORD]}
  1155.  
  1156.     if [ $COMP_CWORD -eq 1 ]; then
  1157.         if [[ "$cur" == -* ]]; then
  1158.             COMPREPLY=( $( compgen -W '--help --version' -- $cur ) ) 
  1159.         else
  1160.             _available_interfaces -w
  1161.         fi
  1162.     else
  1163.         COMPREPLY=( $( compgen -W 'setthr getthr off' -- $cur ) ) 
  1164.     fi
  1165. } &&
  1166. complete -F _iwspy iwspy
  1167.  
  1168. # Linux iwpriv(8) completion
  1169. #
  1170. [ $UNAME = Linux ] && have iwpriv &&
  1171. _iwpriv()
  1172. {
  1173.     local cur prev
  1174.  
  1175.     COMPREPLY=()
  1176.     cur=${COMP_WORDS[COMP_CWORD]}
  1177.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1178.  
  1179.     case "$prev" in
  1180.         roam)
  1181.             COMPREPLY=( $( compgen -W 'on off' -- $cur ) )
  1182.             return 0
  1183.             ;;
  1184.         port)
  1185.             COMPREPLY=( $( compgen -W 'ad-hoc managed' -- $cur ) )
  1186.             return 0
  1187.             ;;
  1188.     esac
  1189.  
  1190.     if [ $COMP_CWORD -eq 1 ]; then
  1191.         if [[ "$cur" == -* ]]; then
  1192.             COMPREPLY=( $( compgen -W '--help --version' -- $cur ) ) 
  1193.         else
  1194.             _available_interfaces -w
  1195.         fi
  1196.     else
  1197.         COMPREPLY=( $( compgen -W '--all roam port' -- $cur ) ) 
  1198.     fi
  1199. } &&
  1200. complete -F _iwpriv iwpriv
  1201.  
  1202. # RedHat & Debian GNU/Linux if{up,down} completion
  1203. #
  1204. [ $UNAME = Linux ] && { have ifup || have ifdown; } &&
  1205. _ifupdown()
  1206. {
  1207.     local cur
  1208.  
  1209.     COMPREPLY=()
  1210.     cur=${COMP_WORDS[COMP_CWORD]}
  1211.  
  1212.     if [ $COMP_CWORD -eq 1 ]; then
  1213.         _configured_interfaces
  1214.        fi
  1215.  
  1216.        return 0
  1217. } &&
  1218. complete -F _ifupdown ifup ifdown
  1219. [ $UNAME = Linux ] && have ifstatus && complete -F _ifupdown ifstatus
  1220.  
  1221. # Linux ipsec(8) completion (for FreeS/WAN)
  1222. #
  1223. [ $UNAME = Linux ] && have ipsec &&
  1224. _ipsec()
  1225. {
  1226.     local cur
  1227.  
  1228.     COMPREPLY=()
  1229.     cur=${COMP_WORDS[COMP_CWORD]}
  1230.  
  1231.     
  1232.     if [ $COMP_CWORD -eq 1 ]; then
  1233.         COMPREPLY=( $( compgen -W 'auto barf eroute klipsdebug look \
  1234.                        manual pluto ranbits rsasigkey \
  1235.                        setup showdefaults showhostkey spi \
  1236.                        spigrp tncfg whack' -- $cur ) )
  1237.         return 0
  1238.     fi
  1239.  
  1240.     case ${COMP_WORDS[1]} in
  1241.     auto)
  1242.         COMPREPLY=( $( compgen -W '--asynchronous --up --add --delete \
  1243.                        --replace --down --route --unroute \
  1244.                        --ready --status --rereadsecrets' \
  1245.                     -- $cur ) )
  1246.         ;;
  1247.     manual)
  1248.         COMPREPLY=( $( compgen -W '--up --down --route --unroute \
  1249.                        --union' -- $cur ) )
  1250.         ;;
  1251.     ranbits)
  1252.         COMPREPLY=( $( compgen -W '--quick --continuous --bytes' \
  1253.                       -- $cur ) )
  1254.         ;;
  1255.     setup)
  1256.         COMPREPLY=( $( compgen -W '--start --stop --restart' -- $cur ) )
  1257.         ;;
  1258.  
  1259.     *)
  1260.         ;;
  1261.     esac
  1262.  
  1263.     return 0
  1264. } &&
  1265. complete -F _ipsec ipsec
  1266.  
  1267. # Postfix completion.
  1268. #
  1269. have postfix && {
  1270. # postfix(1)
  1271. #
  1272. _postfix()
  1273. {
  1274.     local cur prev
  1275.  
  1276.     cur=${COMP_WORDS[COMP_CWORD]}
  1277.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1278.  
  1279.     if [[ $cur == '-' ]]; then
  1280.         COMPREPLY=(-c -D -v)
  1281.         return 0
  1282.     fi
  1283.     if [[ $prev == '-c' ]]; then
  1284.         _filedir -d
  1285.         return 0
  1286.     fi
  1287.     if [[ $prev == '-D' ]]; then
  1288.         COMPREPLY=( $( compgen -W 'start' -- "${COMP_WORDS[COMP_CWORD]}" ) )
  1289.         return 0
  1290.     fi
  1291.     COMPREPLY=( $( compgen -W 'start stop reload abort flush check' -- \
  1292.         "${COMP_WORDS[COMP_CWORD]}" ) )
  1293. }
  1294. complete -F _postfix postfix
  1295.  
  1296. # postalias(1) and postmap(1)
  1297. #
  1298. _postmap()
  1299. {
  1300.     local cur prev len idx
  1301.  
  1302.     cur=${COMP_WORDS[COMP_CWORD]}
  1303.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1304.  
  1305.     if [[ $cur == '-' ]]; then
  1306.         COMPREPLY=(-N -f -i -n -o -p -r -v -w -c -d -q)
  1307.         return 0
  1308.     fi
  1309.     if [[ $prev == '-c' ]]; then
  1310.         _filedir -d
  1311.         return 0
  1312.     fi
  1313.     if [[ $prev == -[dq] ]]; then
  1314.         return 0
  1315.     fi
  1316.  
  1317.     if [[ "$cur" == *:* ]]; then
  1318.                COMPREPLY=( $( compgen -f -- ${cur#*:} ) )
  1319.     else
  1320.         len=${#cur}
  1321.         idx=0
  1322.         for pval in $( /usr/sbin/postconf -m ); do
  1323.             if [[ "$cur" == "${pval:0:$len}" ]]; then
  1324.                 COMPREPLY[$idx]="$pval:"
  1325.                 idx=$(($idx+1))
  1326.             fi
  1327.         done
  1328.         if [[ $idx -eq 0 ]]; then
  1329.             COMPREPLY=( $( compgen -f -- "$cur" ) )
  1330.         fi
  1331.     fi
  1332.     return 0
  1333. }
  1334. complete -F _postmap postmap postalias
  1335.  
  1336. # postcat(1)
  1337. #
  1338. _postcat()
  1339. {
  1340.     local cur prev pval len idx qfile
  1341.  
  1342.     cur=${COMP_WORDS[COMP_CWORD]}
  1343.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1344.  
  1345.     if [[ $cur == '-' ]]; then
  1346.         COMPREPLY=(-c -q -v)
  1347.         return 0
  1348.     fi
  1349.     if [[ $prev == '-c' ]]; then
  1350.         _filedir -d
  1351.         return 0
  1352.     fi
  1353.  
  1354.     qfile=0
  1355.     for idx in ${COMP_WORDS[@]}; do
  1356.         [[ "$idx" = -q ]] && qfile=1 && break
  1357.     done
  1358.     if [[ $qfile == 1 ]]; then
  1359.         len=${#cur}
  1360.         idx=0
  1361.         for pval in $( mailq | \
  1362.             sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do
  1363.             if [[ "$cur" == "${pval:0:$len}" ]]; then
  1364.                 COMPREPLY[$idx]=$pval
  1365.                 idx=$(($idx+1))
  1366.             fi
  1367.         done
  1368.         return 0
  1369.     else
  1370.         _filedir
  1371.         return 0
  1372.     fi
  1373. }
  1374. complete -F _postcat postcat
  1375.  
  1376. # postconf(1)
  1377. #
  1378. _postconf()
  1379. {
  1380.     local cur prev pval len idx eqext
  1381.  
  1382.     cur=${COMP_WORDS[COMP_CWORD]}
  1383.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1384.     if [[ $cur == '-' ]]; then
  1385.         COMPREPLY=(-c -d -e -h -m -l -n -v)
  1386.         return 0
  1387.     fi
  1388.     if [[ $prev == '-c' ]]; then
  1389.         _filedir -d
  1390.         return 0
  1391.     fi
  1392.     if [[ $prev == '-e' ]]; then
  1393.         cur=${cur#[\"\']}
  1394.         eqext='='
  1395.     fi
  1396.     len=${#cur}
  1397.     idx=0
  1398.     for pval in $( /usr/sbin/postconf | cut -d ' ' -f 1 ); do
  1399.         if [[ "$cur" == "${pval:0:$len}" ]]; then
  1400.             COMPREPLY[$idx]="$pval$eqext"
  1401.             idx=$(($idx+1))
  1402.         fi
  1403.     done
  1404.     return 0
  1405. }
  1406. complete -F _postconf postconf
  1407.  
  1408. # postsuper(1)
  1409. #
  1410. _postsuper()
  1411. {
  1412.     local cur prev pval len idx
  1413.  
  1414.     cur=${COMP_WORDS[COMP_CWORD]}
  1415.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1416.  
  1417.     if [[ $cur == '-' ]]; then
  1418.         COMPREPLY=(-c -d -h -H -p -r -s -v)
  1419.         return 0
  1420.     fi
  1421.     case $prev in
  1422.     -[dr])
  1423.         len=${#cur}
  1424.         idx=0
  1425.         for pval in $( echo ALL; mailq | \
  1426.             sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do
  1427.             if [[ "$cur" == "${pval:0:$len}" ]]; then
  1428.                 COMPREPLY[$idx]=$pval
  1429.                 idx=$(($idx+1))
  1430.             fi
  1431.         done
  1432.         return 0
  1433.         ;;
  1434.     -h)
  1435.         len=${#cur}
  1436.         idx=0
  1437.         for pval in $( echo ALL; mailq | \
  1438.             sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* ].*$//; /!$/d' ); do
  1439.             if [[ "$cur" == "${pval:0:$len}" ]]; then
  1440.                 COMPREPLY[$idx]=$pval
  1441.                 idx=$(($idx+1))
  1442.             fi
  1443.         done
  1444.         return 0
  1445.         ;;
  1446.     -H)
  1447.         len=${#cur}
  1448.         idx=0
  1449.         for pval in $( echo ALL; mailq | \
  1450.             sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; /^[0-9A-Z]*[* ]/d; s/!.*$//' ); do
  1451.             if [[ "$cur" == "${pval:0:$len}" ]]; then
  1452.                 COMPREPLY[$idx]=$pval
  1453.                 idx=$(($idx+1))
  1454.             fi
  1455.         done
  1456.         return 0
  1457.         ;;
  1458.     esac
  1459.     COMPREPLY=( $( compgen -W 'hold incoming active deferred' -- $cur ) )
  1460.     return 0
  1461. }
  1462. complete -F _postsuper postsuper
  1463. }
  1464.  
  1465. # cvs(1) completion
  1466. #
  1467. have cvs && {
  1468. set_prefix()
  1469. {
  1470.     [ -z ${prefix:-} ] || prefix=${cur%/*}/
  1471.     [ -r ${prefix:-}CVS/Entries ] || prefix=""
  1472. }
  1473.  
  1474. get_entries()
  1475. {
  1476.     local IFS=$'\n'
  1477.     [ -r ${prefix:-}CVS/Entries ] && \
  1478.     entries=$(cut -d/ -f2 -s ${prefix:-}CVS/Entries)
  1479. }
  1480.  
  1481. get_modules()
  1482. {
  1483.     if [ -n "$prefix" ]; then 
  1484.         COMPREPLY=( $( command ls -d ${cvsroot}/${prefix}/!(CVSROOT) ) )
  1485.     else
  1486.         COMPREPLY=( $( command ls -d ${cvsroot}/!(CVSROOT) ) )
  1487.     fi
  1488. }
  1489.  
  1490. _cvs()
  1491. {
  1492.     local cur count mode i cvsroot cvsroots pwd
  1493.     local -a flags miss files entries changed newremoved
  1494.  
  1495.     COMPREPLY=()
  1496.     cur=${COMP_WORDS[COMP_CWORD]}
  1497.  
  1498.     count=0
  1499.     for i in ${COMP_WORDS[@]}; do
  1500.         [ $count -eq $COMP_CWORD ] && break
  1501.         # Last parameter was the CVSROOT, now go back to mode selection
  1502.         if [ "${COMP_WORDS[((count))]}" == "$cvsroot" -a "$mode" == "cvsroot" ]; then
  1503.             mode=""
  1504.         fi
  1505.         if [ -z "$mode" ]; then
  1506.             case $i in
  1507.             -d)
  1508.                 mode=cvsroot
  1509.                 cvsroot=${COMP_WORDS[((count+1))]}
  1510.                 ;;
  1511.             @(ad?(d)|new))
  1512.                 mode=add
  1513.                 ;;
  1514.             @(adm?(in)|rcs))
  1515.                 mode=admin
  1516.                 ;;
  1517.             ann?(notate))
  1518.                 mode=annotate
  1519.                 ;;
  1520.             @(checkout|co|get))
  1521.                 mode=checkout
  1522.                 ;;
  1523.             @(com?(mit)|ci))
  1524.                 mode=commit
  1525.                 ;;
  1526.             di?(f?(f)))
  1527.                 mode=diff
  1528.                 ;;
  1529.             ex?(p?(ort)))
  1530.                 mode=export
  1531.                 ;;
  1532.             ?(un)edit)
  1533.                 mode=$i
  1534.                 ;;
  1535.             hi?(s?(tory)))
  1536.                 mode=history
  1537.                 ;;
  1538.             im?(p?(ort)))
  1539.                 mode=import
  1540.                 ;;
  1541.             re?(l?(ease)))
  1542.                 mode=release
  1543.                 ;;
  1544.             ?(r)log)
  1545.                 mode=log
  1546.                 ;;
  1547.             @(rdiff|patch))
  1548.                 mode=rdiff
  1549.                 ;;
  1550.             @(remove|rm|delete))
  1551.                 mode=remove
  1552.                 ;;
  1553.             @(rtag|rfreeze))
  1554.                 mode=rtag
  1555.                 ;;
  1556.             st?(at?(us)))
  1557.                 mode=status
  1558.                 ;;
  1559.             @(tag|freeze))
  1560.                 mode=tag
  1561.                 ;;
  1562.             up?(d?(ate)))
  1563.                 mode=update
  1564.                 ;;
  1565.             *)
  1566.                 ;;
  1567.             esac
  1568.         elif [[ "$i" = -* ]]; then
  1569.             flags=( ${flags[@]:-} $i )
  1570.         fi
  1571.         count=$((++count))
  1572.     done
  1573.  
  1574.     case "$mode" in
  1575.     add)
  1576.         if [[ "$cur" != -* ]]; then
  1577.             set_prefix
  1578.             if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then
  1579.                 get_entries
  1580.                 [ -z "$cur" ] && \
  1581.                 files=$( command ls -Ad !(CVS) ) || \
  1582.                 files=$( command ls -d ${cur}* 2>/dev/null )
  1583.                 for i in ${entries[@]:-}; do
  1584.                     files=( ${files[@]/#$i//} )
  1585.                 done
  1586.                 COMPREPLY=( $( compgen -W '${files[@]}' -- \
  1587.                            $cur ) )
  1588.             fi
  1589.         else
  1590.             COMPREPLY=( $( compgen -W '-k -m' -- $cur ) )
  1591.         fi
  1592.         ;;
  1593.     admin)
  1594.         if [[ "$cur" = -* ]]; then
  1595.             COMPREPLY=( $( compgen -W '-i -a -A -e -b -c -k -l -u \
  1596.                            -L -U -m -M -n -N -o -q -I \
  1597.                            -s -t -t- -T -V -x -z' -- \
  1598.                     $cur ) )
  1599.         fi
  1600.         ;;
  1601.     annotate)
  1602.         if [[ "$cur" = -* ]]; then
  1603.             COMPREPLY=( $( compgen -W '-D -F -f -l -R -r' -- $cur ) )
  1604.         else
  1605.             get_entries
  1606.             COMPREPLY=( $( compgen -W '${entries[@]}' -- $cur ) )
  1607.         fi
  1608.         ;;
  1609.     checkout)
  1610.         if [[ "$cur" != -* ]]; then
  1611.             [ -z "$cvsroot" ] && cvsroot=$CVSROOT
  1612.             COMPREPLY=( $( cvs -d "$cvsroot" co -c 2> /dev/null | \
  1613.                     awk '{print $1}' ) )
  1614.             COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- $cur ) )
  1615.         else
  1616.             COMPREPLY=( $( compgen -W '-A -N -P -R -c -f -l -n -p \
  1617.                           -s -r -D -d -k -j' -- $cur ) )
  1618.         fi
  1619.         ;;
  1620.     commit)
  1621.         set_prefix
  1622.  
  1623.         if [[ "$cur" != -* ]] && [ -r ${prefix:-}CVS/Entries ]; then
  1624.             # if $COMP_CVS_REMOTE is not null, 'cvs commit' will
  1625.             # complete on remotely checked-out files (requires
  1626.             # passwordless access to the remote repository
  1627.             if [ -n "${COMP_CVS_REMOTE:-}" ]; then
  1628.                 # this is the least computationally intensive
  1629.                 # way found so far, but other changes
  1630.                 # (something other than changed/removed/new)
  1631.                 # may be missing
  1632.                 changed=( $( cvs -q diff --brief 2>&1 | \
  1633.                 sed -ne 's/^Files [^ ]* and \([^ ]*\) differ$/\1/p' ) )
  1634.                 newremoved=( $( cvs -q diff --brief 2>&1 | \
  1635.                 sed -ne 's/^cvs diff: \([^ ]*\) .*, no comparison available$/\1/p' ) )
  1636.                 COMPREPLY=( $( compgen -W '${changed[@]:-} \
  1637.                            ${newremoved[@]:-}' -- $cur ) )
  1638.             else
  1639.                 _filedir
  1640.             fi
  1641.         else
  1642.             COMPREPLY=( $( compgen -W '-n -R -l -f -F -m -r' -- \
  1643.                        $cur ) )
  1644.         fi
  1645.         ;;
  1646.     cvsroot)
  1647.         if [ -r ~/.cvspass ]; then
  1648.             # Ugly escaping because of bash treating ':' specially
  1649.             cvsroots=$( sed 's/^[^ ]* //; s/:/\\:/g' ~/.cvspass )
  1650.             COMPREPLY=( $( compgen -W '$cvsroots' -- $cur ) )
  1651.         fi
  1652.         ;;
  1653.     export)
  1654.         if [[ "$cur" != -* ]]; then
  1655.             [ -z "$cvsroot" ] && cvsroot=$CVSROOT
  1656.             COMPREPLY=( $( cvs -d "$cvsroot" co -c | awk '{print $1}' ) )
  1657.             COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- $cur ) )
  1658.         else
  1659.             COMPREPLY=( $( compgen -W '-N -f -l -R -n \
  1660.                           -r -D -d -k' -- $cur ) )
  1661.         fi
  1662.         ;;
  1663.     diff)
  1664.         if [[ "$cur" == -* ]]; then
  1665.             _longopt diff
  1666.         else
  1667.             get_entries
  1668.             COMPREPLY=( $( compgen -W '${entries[@]:-}' -- $cur ) )
  1669.         fi
  1670.         ;;
  1671.     remove)
  1672.         if [[ "$cur" != -* ]]; then
  1673.             set_prefix
  1674.             if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then
  1675.                 get_entries
  1676.                 # find out what files are missing
  1677.                 for i in ${entries[@]}; do
  1678.                     [ ! -r "$i" ] && miss=( ${miss[@]:-} $i )
  1679.                 done
  1680.                 COMPREPLY=( $(compgen -W '${miss[@]:-}' -- $cur) )
  1681.             fi
  1682.         else
  1683.             COMPREPLY=( $( compgen -W '-f -l -R' -- $cur ) )
  1684.         fi
  1685.         ;;
  1686.     import)
  1687.         if [[ "$cur" != -* ]]; then
  1688.             # starts with same algorithm as checkout
  1689.             [ -z "$cvsroot" ] && cvsroot=$CVSROOT
  1690.             prefix=${cur%/*}
  1691.             if [ -r ${cvsroot}/${prefix} ]; then
  1692.                 get_modules
  1693.                 COMPREPLY=( ${COMPREPLY[@]#$cvsroot} )
  1694.                 COMPREPLY=( ${COMPREPLY[@]#\/} )
  1695.             fi
  1696.             pwd=$( pwd )
  1697.             pwd=${pwd##*/}
  1698.             COMPREPLY=( $( compgen -W '${COMPREPLY[@]} $pwd' -- \
  1699.                        $cur ) )
  1700.         else
  1701.             COMPREPLY=( $( compgen -W '-d -k -I -b -m -W' -- $cur ))
  1702.         fi
  1703.         ;;
  1704.     update)
  1705.         if [[ "$cur" = -* ]]; then
  1706.             COMPREPLY=( $( compgen -W '-A -P -C -d -f -l -R -p \
  1707.                            -k -r -D -j -I -W' -- \
  1708.                            $cur ) )
  1709.         fi
  1710.         ;;
  1711.     "")
  1712.         COMPREPLY=( $( compgen -W 'add admin annotate checkout ci co \
  1713.                        commit diff delete edit export \
  1714.                        freeze get history import log new \
  1715.                        patch rcs rdiff release remove \
  1716.                        rfreeze rlog rm rtag stat status \
  1717.                        tag unedit up update -H -Q -q -b \
  1718.                        -d -e -f -l -n -t -r -v -w -x -z \
  1719.                        --help --version' -- $cur ) )
  1720.         ;;
  1721.     *)
  1722.         ;;
  1723.     esac
  1724.     
  1725.     return 0
  1726. }
  1727. complete -F _cvs $default cvs
  1728. }
  1729.  
  1730. have rpm && {
  1731. # helper functions for rpm completion
  1732. #
  1733. _rpm_installed_packages()
  1734. {
  1735.     local ver nodig nosig
  1736.  
  1737.     if [ -r /var/log/rpmpkgs -a \
  1738.         /var/log/rpmpkgs -nt /var/lib/rpm/Packages ]; then
  1739.         # using RHL 7.2 or later - this is quicker than querying the DB
  1740.         COMPREPLY=( $( sed -ne \
  1741.         's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+.*\.rpm$|\1|p' \
  1742.                 /var/log/rpmpkgs ) )
  1743.     else
  1744.         nodig=""
  1745.         nosig=""
  1746.         ver=$(rpm --version)
  1747.         ver=${ver##* }
  1748.       
  1749.         if [[ "$ver" > "4.0.4" ]]; then
  1750.             nodig="--nodigest"
  1751.         fi
  1752.         if [[ "$ver" > "4.0.99" ]]; then
  1753.             nosig="--nosignature"
  1754.         fi
  1755.  
  1756.         COMPREPLY=( $( rpm -qa $nodig $nosig | sed -ne \
  1757.         's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+$|\1|p' ) )
  1758.     fi
  1759. }
  1760.  
  1761. _rpm_groups()
  1762. {
  1763.     local IFS=$'\t'
  1764.     # remove trailing backslash, or grep will complain
  1765.     cur=${cur%"\\"}
  1766.     COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat '%{group}\n' | \
  1767.                grep "^$cur" ) )
  1768.     # backslash escape spaces and translate newlines to tabs
  1769.     COMPREPLY=( $( echo ${COMPREPLY[@]} | sed 's/ /\\ /g' | tr '\n' '\t' ) )
  1770. }
  1771.  
  1772. # rpm(8) completion
  1773. _rpm()
  1774. {
  1775.     local cur prev ver nodig nosig
  1776.  
  1777.     COMPREPLY=()
  1778.     cur=${COMP_WORDS[COMP_CWORD]}
  1779.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1780.     nodig=""
  1781.     nosig=""
  1782.     ver=$(rpm --version); ver=${ver##* }
  1783.   
  1784.     if [[ "$ver" > "4.0.4" ]]; then
  1785.         nodig="--nodigest"
  1786.     fi
  1787.     if [[ "$ver" > "4.0.99" ]]; then
  1788.         nosig="--nosignature"
  1789.     fi
  1790.  
  1791.     if [ $COMP_CWORD -eq 1 ]; then
  1792.         # first parameter on line
  1793.         case "$cur" in
  1794.         -b*)
  1795.             COMPREPLY=( $( compgen -W '-ba -bb -bc -bi -bl -bp -bs'\
  1796.                        -- $cur ) )
  1797.             ;;
  1798.         -t*)
  1799.             COMPREPLY=( $( compgen -W '-ta -tb -tc -ti -tl -tp -ts'\
  1800.                        -- $cur ) )
  1801.             ;;
  1802.         --*)
  1803.             COMPREPLY=( $( compgen -W '--help --version --initdb \
  1804.             --checksig --recompile --rebuild --resign --addsign \
  1805.             --rebuilddb --showrc --setperms --setugids --tarbuild \
  1806.             --eval --install --upgrade --query --freshen --erase \
  1807.             --verify --querytags --rmsource --rmspec --clean \
  1808.             --import' -- $cur ) )
  1809.             ;;
  1810.         *)
  1811.             COMPREPLY=( $( compgen -W '-b -e -F -i -q -t -U -V' \
  1812.                        -- $cur ) )
  1813.             ;;
  1814.         esac
  1815.  
  1816.     return 0
  1817.     fi
  1818.  
  1819.     case "$prev" in
  1820.     --@(@(db|exclude)path|prefix|relocate|root))
  1821.         _filedir -d
  1822.         return 0
  1823.         ;;
  1824.     --eval)
  1825.         # get a list of macros
  1826.         COMPREPLY=( $( sed -ne 's|^\(%'${cur#\%}'[^ '$'\t'']*\).*$|\1|p' \
  1827.                    /usr/lib/rpm/macros ) )
  1828.         return 0
  1829.         ;;
  1830.     --pipe)
  1831.         COMPREPLY=( $( compgen -c -- $cur ) )
  1832.         return 0
  1833.         ;;
  1834.     --rcfile)
  1835.         _filedir
  1836.         return 0
  1837.         ;;
  1838.     --specfile)
  1839.         # complete on .spec files
  1840.         _filedir spec
  1841.         return 0
  1842.         ;;
  1843.     --whatprovides)
  1844.         if [[ "$cur" == */* ]]; then
  1845.             _filedir
  1846.         else
  1847.         # complete on capabilities
  1848.             COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat \
  1849.                     '%{providename}\n' | grep "^$cur" ) )
  1850.         fi
  1851.         return 0
  1852.         ;;
  1853.     --whatrequires)
  1854.         # complete on capabilities
  1855.         COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat \
  1856.                 '%{requirename}\n' | grep "^$cur" ) )
  1857.         return 0
  1858.         ;;
  1859.     esac
  1860.  
  1861.     case "${COMP_WORDS[1]}" in
  1862.     -@([iFU]*|-install|-freshen|-upgrade))
  1863.         if [[ "$cur" == -* ]]; then
  1864.             COMPREPLY=( $( compgen -W '--percent --force --test \
  1865.             --replacepkgs --replacefiles --root --excludedocs \
  1866.             --includedocs --noscripts --rcfile --ignorearch \
  1867.             --dbpath --prefix --ignoreos --nodeps --allfiles \
  1868.             --ftpproxy --ftpport --justdb --httpproxy --httpport \
  1869.             --noorder --relocate --badreloc --notriggers \
  1870.             --excludepath --ignoresize --oldpackage --define \
  1871.             --eval --pipe --queryformat --repackage --nosuggests \
  1872.             --nodigest --nosignature' -- $cur ) )
  1873.         else
  1874.             _filedir 'rpm'
  1875.         fi
  1876.         ;;
  1877.     -@(e|-erase))
  1878.         if [[ "$cur" == -* ]]; then
  1879.             COMPREPLY=( $( compgen -W '--allmatches --noscripts \
  1880.             --notriggers --nodeps --test --repackage' -- $cur ) )
  1881.         else
  1882.             _rpm_installed_packages
  1883.         fi
  1884.         ;;
  1885.     -@(q*|-query))
  1886.         # check whether we're doing file completion
  1887.         if [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then
  1888.             if [[ "$cur" == -* ]]; then
  1889.             COMPREPLY=( $( compgen -W '--scripts --root \
  1890.                 --rcfile --requires --ftpport --ftpproxy \
  1891.                 --httpproxy --httpport --provides --triggers \
  1892.                 --dump --changelog --dbpath \
  1893.                 --last --filesbypkg \
  1894.                 --info --list --state \
  1895.                 --docfiles --configfiles --queryformat \
  1896.                 --conflicts --obsoletes \
  1897.                 --nodigest --nosignature \
  1898.                 --triggerscripts' -- $cur ) )
  1899.             else
  1900.             _filedir
  1901.             fi
  1902.         elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then
  1903.             _rpm_groups
  1904.         elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then
  1905.             # uninstalled package completion
  1906.             if [[ "$cur" == -* ]]; then
  1907.                 COMPREPLY=( $( compgen -W '--scripts --root \
  1908.                 --rcfile --whatprovides --whatrequires \
  1909.                 --requires --triggeredby --ftpport --ftpproxy \
  1910.                 --httpproxy --httpport --provides --triggers \
  1911.                 --dump --changelog --dbpath --filesbypkg \
  1912.                 --define --eval --pipe --showrc --info --list \
  1913.                 --state --docfiles --configfiles --queryformat\
  1914.                 --conflicts --obsoletes --nodigest \
  1915.                 --nosignature' -- $cur ) )
  1916.             else
  1917.                 _filedir 'rpm'
  1918.             fi
  1919.         else
  1920.             # installed package completion
  1921.             if [[ "$cur" == -* ]]; then
  1922.                 COMPREPLY=( $( compgen -W '--scripts --root \
  1923.                 --rcfile --whatprovides --whatrequires \
  1924.                 --requires --triggeredby --ftpport --ftpproxy \
  1925.                 --httpproxy --httpport --provides --triggers \
  1926.                 --dump --changelog --dbpath --specfile \
  1927.                 --querybynumber --last --filesbypkg --define \
  1928.                 --eval --pipe --showrc --info --list --state \
  1929.                 --docfiles --configfiles --queryformat \
  1930.                 --conflicts --obsoletes --pkgid --hdrid \
  1931.                 --fileid --tid --nodigest --nosignature \
  1932.                 --triggerscripts' -- $cur ) )
  1933.             elif [ "${COMP_LINE#* -*([^ -])a}" == "$COMP_LINE" ]; then
  1934.                 _rpm_installed_packages
  1935.             fi
  1936.         fi
  1937.         ;;
  1938.     -@(K*|-checksig))
  1939.         if [[ "$cur" == -* ]]; then
  1940.             COMPREPLY=( $( compgen -W '--nopgp --nogpg --nomd5 \
  1941.                     --nodigest --nosignature' -- $cur ) )
  1942.         else
  1943.             _filedir 'rpm'
  1944.         fi
  1945.         ;;
  1946.     -@([Vy]*|-verify))
  1947.         if [[ "$cur" == -* ]]; then
  1948.             COMPREPLY=( $( compgen -W '--root --rcfile --dbpath \
  1949.             --nodeps --nogroup --nolinkto --nomode --nomtime \
  1950.             --nordev --nouser --nofiles --noscripts --nomd5 \
  1951.             --querytags --specfile --whatrequires --whatprovides \
  1952.             --nodigest --nosignature' -- $cur ) )
  1953.         # check whether we're doing file completion
  1954.         elif [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then
  1955.             _filedir
  1956.         elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then
  1957.             _rpm_groups
  1958.         elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then
  1959.             _filedir 'rpm'
  1960.         else
  1961.             _rpm_installed_packages
  1962.         fi
  1963.         ;;
  1964.     -[bt]*)
  1965.         if [[ "$cur" == -* ]]; then
  1966.             COMPREPLY=( $( compgen -W '--short-circuit --timecheck \
  1967.             --clean --rmsource --rmspec --test --sign --buildroot \
  1968.             --target -- buildarch --buildos --nobuild --nodeps \
  1969.             --nodirtokens' -- $cur ) )
  1970.         elif [[ ${COMP_WORDS[1]} == -b* ]]; then
  1971.             _filedir 'spec'
  1972.         else
  1973.             _filedir '@(tgz|tar.@(gz|bz2))'
  1974.         fi
  1975.         ;;
  1976.     --re@(build|compile))
  1977.         if [[ "$cur" == -* ]]; then
  1978.             COMPREPLY=( $( compgen -W '--nodeps --rmsource \
  1979.               --rmspec --sign --nodirtokens --target' -- $cur ) )
  1980.         else
  1981.             _filedir '?(no)src.rpm'
  1982.         fi
  1983.         ;;
  1984.     --tarbuild)
  1985.         _filedir '@(tgz|tar.@(gz|bz2))'
  1986.         ;;
  1987.     --@(re|add)sign)
  1988.         _filedir 'rpm'
  1989.         ;;
  1990.     --set@(perms|gids))
  1991.         _rpm_installed_packages
  1992.         ;;
  1993.     --@(clean|rms@(ource|pec)))
  1994.         if [[ "$cur" == -* ]]; then
  1995.             COMPREPLY=( $( compgen -W '--clean --rmsource \
  1996.                     --rmspec' -- $cur ) )
  1997.         else
  1998.             _filedir 'spec'
  1999.         fi
  2000.         ;;
  2001.     --@(import|dbpath|root))
  2002.         if [[ "$cur" == -* ]]; then
  2003.             COMPREPLY=( $( compgen -W '--import --dbpath --root' \
  2004.                     -- $cur ) )
  2005.         else
  2006.             _filedir
  2007.         fi
  2008.         ;;
  2009.     esac
  2010.  
  2011.     return 0
  2012. }
  2013. complete -F _rpm $filenames rpm rpmbuild
  2014. }
  2015.  
  2016. # Debian apt-get(8) completion.
  2017. #
  2018. have apt-get &&
  2019. _apt_get()
  2020. {
  2021.     local cur prev special i
  2022.  
  2023.     COMPREPLY=()
  2024.     cur=${COMP_WORDS[COMP_CWORD]}
  2025.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2026.  
  2027.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  2028.         if [[ ${COMP_WORDS[i]} == @(install|remove|source|build-dep) ]]; then
  2029.             special=${COMP_WORDS[i]}
  2030.         fi
  2031.     done
  2032.  
  2033.     if [ -n "$special" ]; then
  2034.         case $special in
  2035.         remove)
  2036.             if [ -f /etc/debian_version ]; then
  2037.                 # Debian system
  2038.                 COMPREPLY=( $( _comp_dpkg_installed_packages \
  2039.                         $cur ) )
  2040.             else
  2041.                 # assume RPM based
  2042.                 _rpm_installed_packages
  2043.             fi
  2044.             return 0
  2045.             ;;
  2046.         *)
  2047.             COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
  2048.             return 0
  2049.             ;;
  2050.  
  2051.         esac
  2052.     fi
  2053.  
  2054.     case "$prev" in
  2055.         -@(c|-config-file))
  2056.               _filedir
  2057.              return 0
  2058.              ;;
  2059.  
  2060.         -@(t|-target-release|-default-release))
  2061.              COMPREPLY=( $( apt-cache policy | \
  2062.                     grep "release.o=Debian,a=$cur" | \
  2063.                     sed -e "s/.*a=\(\w*\).*/\1/" | uniq 2> /dev/null) )
  2064.              return 0
  2065.              ;;
  2066.  
  2067.     esac
  2068.  
  2069.     if [[ "$cur" == -* ]]; then
  2070.  
  2071.         COMPREPLY=( $( compgen -W '-d -f -h -v -m -q -s -y \
  2072.                 -u -t -b -c -o --download-only --fix-broken \
  2073.                 --help --version --ignore-missing \
  2074.                 --fix-missing --no-download --quiet --simulate \
  2075.                 --just-print --dry-run --recon --no-act --yes \
  2076.                 --assume-yes --show-upgraded --only-source \
  2077.                 --compile --build --ignore-hold \
  2078.                 --target-release --no-upgrade --force-yes \
  2079.                 --print-uris --purge --reinstall \
  2080.                 --list-cleanup --default-release \
  2081.                 --trivial-only --no-remove --diff-only \
  2082.                 --tar-only --config-file --option' -- $cur ) )
  2083.     else
  2084.  
  2085.         COMPREPLY=( $( compgen -W 'update upgrade dselect-upgrade \
  2086.                 dist-upgrade install remove source build-dep \
  2087.                 check clean autoclean autoremove' -- $cur ) )
  2088.  
  2089.     fi
  2090.  
  2091.  
  2092.     return 0
  2093. } &&
  2094. complete -F _apt_get $filenames apt-get
  2095.  
  2096. # Debian apt-cache(8) completion.
  2097. #
  2098. have apt-cache &&
  2099. _apt_cache()
  2100. {
  2101.     local cur prev special i
  2102.  
  2103.     COMPREPLY=()
  2104.     cur=${COMP_WORDS[COMP_CWORD]}
  2105.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2106.  
  2107.     
  2108.     if [ "$cur" != show ]; then
  2109.         for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  2110.         if [[ ${COMP_WORDS[i]} == @(add|depends|dotty|policy|rdepends|madison|show?(pkg|src|)) ]]; then
  2111.             special=${COMP_WORDS[i]}
  2112.         fi
  2113.         done
  2114.     fi
  2115.  
  2116.  
  2117.     if [ -n "$special" ]; then
  2118.         case $special in
  2119.         add)
  2120.             _filedir
  2121.             return 0
  2122.             ;;
  2123.         
  2124.          *)
  2125.             COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
  2126.             return 0
  2127.             ;;
  2128.         
  2129.         esac
  2130.     fi
  2131.  
  2132.  
  2133.     case "$prev" in
  2134.          -@(c|p|s|-config-file|-@(pkg|src)-cache))
  2135.              _filedir
  2136.              return 0
  2137.              ;;
  2138.          search)
  2139.              if [[ "$cur" != -* ]]; then
  2140.                 return 0
  2141.              fi
  2142.              ;;
  2143.     esac
  2144.  
  2145.     if [[ "$cur" == -* ]]; then
  2146.  
  2147.         COMPREPLY=( $( compgen -W '-h -v -p -s -q -i -f -a -g -c \
  2148.                 -o --help --version --pkg-cache --src-cache \
  2149.                 --quiet --important --full --all-versions \
  2150.                 --no-all-versions --generate --no-generate \
  2151.                 --names-only --all-names --recurse \
  2152.                 --config-file --option' -- $cur ) )
  2153.     else
  2154.  
  2155.         COMPREPLY=( $( compgen -W 'add gencaches show showpkg showsrc \
  2156.                 stats dump dumpavail unmet search search \
  2157.                 depends rdepends pkgnames dotty xvcg \
  2158.                 policy madison' -- $cur ) )
  2159.  
  2160.     fi
  2161.  
  2162.  
  2163.     return 0
  2164. } &&
  2165. complete -F _apt_cache $filenames apt-cache
  2166.  
  2167.  
  2168. # Debian aptitude(1) completion
  2169. #
  2170. have aptitude && {
  2171. have grep-status && {
  2172. _comp_dpkg_hold_packages()
  2173. {
  2174.     grep-status -P -e "^$1" -a -FStatus 'hold' -n -s Package
  2175. }
  2176. } || {
  2177. _comp_dpkg_hold_packages()
  2178. {
  2179.     grep -B 2 'hold' /var/lib/dpkg/status | grep "Package: $1" \
  2180.         | cut -d\  -f2
  2181. }
  2182. }
  2183.  
  2184. _aptitude()
  2185. {
  2186.     local cur dashoptions prev special i
  2187.  
  2188.     COMPREPLY=()
  2189.     cur=${COMP_WORDS[COMP_CWORD]}
  2190.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2191.  
  2192.  
  2193.     dashoptions='-S -u -i -h --help --version -s --simulate -d \
  2194.              --download-only -P --prompt -y --assume-yes -F \
  2195.              --display-format -O --sort -w --width -f -r -g \
  2196.              --with-recommends --with-suggests -R -G \
  2197.              --without-recommends --without-suggests -t \
  2198.              --target-release -V --show-versions -D --show-deps\
  2199.              -Z -v --verbose'
  2200.  
  2201.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  2202.         if [[ ${COMP_WORDS[i]} == @(install|reinstall|hold|unhold|markauto|unmarkauto|dist-upgrade|download|show|forbid-version|purge|remove|changelog) ]]; then
  2203.         special=${COMP_WORDS[i]}
  2204.         fi
  2205.         #exclude some mutually exclusive options
  2206.         [[ ${COMP_WORDS[i]} == '-u' ]] && dashoptions=${dashoptions/-i}
  2207.         [[ ${COMP_WORDS[i]} == '-i' ]] && dashoptions=${dashoptions/-u}
  2208.     done
  2209.  
  2210.     if [[ -n "$special" ]]; then
  2211.        case $special in
  2212.            @(install|hold|markauto|unmarkauto|dist-upgrade|download|show|changelog))
  2213.            COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
  2214.            return 0
  2215.            ;;
  2216.            @(purge|remove|reinstall|forbid-version))
  2217.              COMPREPLY=( $( _comp_dpkg_installed_packages $cur ) )
  2218.            return 0
  2219.            ;;
  2220.            unhold)
  2221.              COMPREPLY=( $( _comp_dpkg_hold_packages $cur ) )
  2222.            return 0
  2223.            ;;
  2224.  
  2225.        esac
  2226.     fi
  2227.  
  2228.     case $prev in
  2229.         # don't complete anything if these options are found
  2230.         @(autoclean|clean|forget-new|search|upgrade|update))
  2231.         return 0
  2232.         ;;
  2233.  
  2234.         -S)
  2235.         _filedir
  2236.         return 0
  2237.         ;;
  2238.  
  2239.         -@(t|-target-release|-default-release))
  2240.         COMPREPLY=( $( apt-cache policy | \
  2241.             grep "release.o=Debian,a=$cur" | \
  2242.             sed -e "s/.*a=\(\w*\).*/\1/" | uniq 2> /dev/null ) )
  2243.         return 0
  2244.         ;;
  2245.  
  2246.     esac
  2247.  
  2248.     if [[ "$cur" == -* ]]; then
  2249.         COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )
  2250.     else
  2251.         COMPREPLY=( $( compgen -W 'update upgrade forget-new clean \
  2252.                        autoclean install reinstall remove \
  2253.                        hold unhold purge markauto unmarkauto \
  2254.                        dist-upgrade download search show \
  2255.                        forbid-version changelog' -- $cur ) )
  2256.     fi
  2257.  
  2258.  
  2259.     return 0
  2260. }
  2261. complete -F _aptitude $default aptitude
  2262. }
  2263.  
  2264. # Debian apt-build(1) completion.
  2265. #
  2266. have apt-build &&
  2267. _apt_build()
  2268. {
  2269.     local cur prev special i
  2270.  
  2271.     COMPREPLY=()
  2272.     cur=${COMP_WORDS[COMP_CWORD]}
  2273.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2274.  
  2275.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  2276.         if [[ ${COMP_WORDS[i]} == @(install|remove|source|info|clean) ]]; then
  2277.             special=${COMP_WORDS[i]}
  2278.         fi
  2279.     done
  2280.  
  2281.     if [ -n "$special" ]; then
  2282.         case $special in
  2283.         @(install|source|info))
  2284.             COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
  2285.             return 0
  2286.             ;;
  2287.         remove)
  2288.             COMPREPLY=( $( _comp_dpkg_installed_packages \
  2289.                     $cur ) )
  2290.             return 0
  2291.             ;;
  2292.         *)
  2293.             return 0
  2294.             ;;
  2295.         esac
  2296.     fi
  2297.  
  2298.     case "$prev" in
  2299.  
  2300.          --@(patch|build-dir|repository-dir))
  2301.            _filedir
  2302.            return 0
  2303.            ;;
  2304.  
  2305.          -@(h|-help))
  2306.            return 0
  2307.            ;;
  2308.  
  2309.     esac
  2310.  
  2311.     if [[ "$cur" == -* ]]; then
  2312.         COMPREPLY=( $( compgen -W '--help --show-upgraded -u --build-dir \
  2313.                   --repository-dir --build-only \
  2314.                   --build-command --reinstall --rebuild \
  2315.                   --remove-builddep --no-wrapper --purge \
  2316.                   --patch --patch-strip -p --yes -y \
  2317.                   --version -v --no-source' -- $cur ) )
  2318.  
  2319.     else
  2320.         COMPREPLY=( $( compgen -W 'update upgrade install remove \
  2321.                   source dist-upgrade world clean info \
  2322.                   clean-build update-repository ' -- $cur ) )
  2323.     fi
  2324.  
  2325.  
  2326.     return 0
  2327. } &&
  2328. complete -F _apt_build $filenames apt-build
  2329.  
  2330. # chsh(1) completion
  2331. #
  2332. _chsh()
  2333. {
  2334.     local cur prev
  2335.  
  2336.     COMPREPLY=()
  2337.     cur=${COMP_WORDS[COMP_CWORD]}
  2338.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2339.  
  2340.     if [ "$prev" = "-s" ]; then
  2341.       if [ -f /etc/debian_version ]; then
  2342.         COMPREPLY=( $( </etc/shells ) )
  2343.       else
  2344.         COMPREPLY=( $( chsh -l | grep "^$cur" ) )
  2345.       fi
  2346.     else
  2347.       COMPREPLY=( $( compgen -u -- $cur ) )
  2348.     fi
  2349.  
  2350.     return 0
  2351. }
  2352. complete -F _chsh chsh
  2353.  
  2354. # chkconfig(8) completion
  2355. #
  2356. have chkconfig &&
  2357. _chkconfig()
  2358. {
  2359.     local cur prev
  2360.  
  2361.     COMPREPLY=()
  2362.     cur=${COMP_WORDS[COMP_CWORD]}
  2363.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2364.  
  2365.     case "$prev" in
  2366.     @([1-6]|--@(list|add|del)))
  2367.         _services
  2368.         return 0
  2369.         ;;
  2370.     --level)
  2371.         COMPREPLY=( $( compgen -W '1 2 3 4 5 6' -- $cur ) )
  2372.         return 0
  2373.         ;;
  2374.     esac
  2375.  
  2376.     if [[ "$cur" == -* ]]; then
  2377.         COMPREPLY=( $( compgen -W '--list --add --del --level' -- $cur ) )
  2378.     else
  2379.         if [ $COMP_CWORD -eq 2 -o $COMP_CWORD -eq 4 ]; then
  2380.             COMPREPLY=( $( compgen -W 'on off reset' -- $cur ) )
  2381.         else
  2382.             _services
  2383.         fi
  2384.     fi
  2385. } &&
  2386. complete -F _chkconfig chkconfig
  2387.  
  2388. # This function provides simple user@host completion
  2389. #
  2390. _user_at_host() {
  2391.     local cur
  2392.  
  2393.     COMPREPLY=()
  2394.     cur=${COMP_WORDS[COMP_CWORD]}
  2395.  
  2396.     if [[ $cur == *@* ]]; then
  2397.         _known_hosts
  2398.     else
  2399.         COMPREPLY=( $( compgen -u -- "$cur" ) )
  2400.     fi
  2401.  
  2402.     return 0
  2403. }
  2404. shopt -u hostcomplete && complete -F _user_at_host $nospace talk ytalk finger
  2405.  
  2406. # This function performs host completion based on ssh's known_hosts files,
  2407. # defaulting to standard host completion if they don't exist.
  2408. #
  2409. _known_hosts()
  2410. {
  2411.        local cur curd ocur user suffix aliases global_kh user_kh hosts i host
  2412.        local -a kh khd config
  2413.  
  2414.     COMPREPLY=()
  2415.     cur=${COMP_WORDS[COMP_CWORD]}
  2416.     ocur=$cur
  2417.  
  2418.     [ "$1" = -a ] || [ "$2" = -a ] && aliases='yes'
  2419.     [ "$1" = -c ] || [ "$2" = -c ] && suffix=':'
  2420.     [[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@}
  2421.     kh=()
  2422.  
  2423.     # ssh config files
  2424.     [ -r /etc/ssh/ssh_config ] &&
  2425.       config=( ${config[@]} /etc/ssh/ssh_config )
  2426.     [ -r ~/.ssh/config ] &&
  2427.       config=( ${config[@]} ~/.ssh/config )
  2428.     [ -r ~/.ssh2/config ] &&
  2429.       config=( ${config[@]} ~/.ssh2/config )
  2430.  
  2431.     if [ ${#config[@]} -gt 0 ]; then
  2432.         # expand path (if present) to global known hosts file
  2433.         global_kh=$( eval echo $( sed -ne 's/^[Gg][Ll][Oo][Bb][Aa][Ll][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/\1/p' ${config[@]} ) )
  2434.         # expand path (if present) to user known hosts file
  2435.         user_kh=$( eval echo $( sed -ne 's/^[Uu][Ss][Ee][Rr][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/\1/p' ${config[@]} ) )
  2436.     fi
  2437.  
  2438.     # choose which global known hosts file to use
  2439.     if [ -r "$global_kh" ]; then
  2440.         kh=( "$global_kh" )
  2441.     else
  2442.         [ -r /etc/ssh/ssh_known_hosts ] &&
  2443.           kh=( ${kh[@]} /etc/ssh/ssh_known_hosts )
  2444.         [ -r /etc/ssh/ssh_known_hosts2 ] &&
  2445.           kh=( ${kh[@]} /etc/ssh/ssh_known_hosts2 )
  2446.         [ -r /etc/known_hosts ] &&
  2447.           kh=( ${kh[@]} /etc/known_hosts )
  2448.         [ -r /etc/known_hosts2 ] &&
  2449.           kh=( ${kh[@]} /etc/known_hosts2 )
  2450.         [ -d /etc/ssh2/knownhosts ] &&
  2451.           khd=( ${khd[@]} /etc/ssh2/knownhosts/*pub )
  2452.     fi
  2453.  
  2454.     # choose which user known hosts file to use
  2455.     if [ -r "$user_kh" ]; then
  2456.         kh=( ${kh[@]} "$user_kh" )
  2457.     else
  2458.         [ -r ~/.ssh/known_hosts ] &&
  2459.           kh=( ${kh[@]} ~/.ssh/known_hosts )
  2460.         [ -r ~/.ssh/known_hosts2 ] &&
  2461.           kh=( ${kh[@]} ~/.ssh/known_hosts2 )
  2462.         [ -d ~/.ssh2/hostkeys ] &&
  2463.           khd=( ${khd[@]} ~/.ssh2/hostkeys/*pub )
  2464.     fi
  2465.  
  2466.     # If we have known_hosts files to use
  2467.     if [ ${#kh[@]} -gt 0 -o ${#khd[@]} -gt 0 ]; then
  2468.         # Escape slashes and dots in paths for awk
  2469.         cur=${cur//\//\\\/}
  2470.         cur=${cur//\./\\\.}
  2471.         curd=$cur
  2472.  
  2473.         if [[ "$cur" == [0-9]*.* ]]; then
  2474.         # Digits followed by a dot - just search for that
  2475.         cur="^$cur.*"
  2476.         elif [[ "$cur" == [0-9]* ]]; then
  2477.         # Digits followed by no dot - search for digits followed
  2478.         # by a dot
  2479.         cur="^$cur.*\."
  2480.         elif [ -z "$cur" ]; then
  2481.         # A blank - search for a dot or an alpha character
  2482.         cur="[a-z.]"
  2483.         else
  2484.         cur="^$cur"
  2485.         fi
  2486.  
  2487.         if [ ${#kh[@]} -gt 0 ]; then
  2488.  
  2489.         # FS needs to look for a comma separated list
  2490.         COMPREPLY=( $( awk 'BEGIN {FS=","}
  2491.                 {for (i=1; i<=2; ++i) { \
  2492.                        gsub(" .*$", "", $i); \
  2493.                        if ($i ~ /'$cur'/) {print $i} \
  2494.                 }}' ${kh[@]} 2>/dev/null ) )
  2495.         fi
  2496.         if [ ${#khd[@]} -gt 0 ]; then
  2497.         # Needs to look for files called
  2498.         # .../.ssh2/key_22_<hostname>.pub
  2499.         # dont fork any processes, because in a cluster environment, 
  2500.         # there can be hundreds of hostkeys
  2501.         for i in ${khd[@]} ; do
  2502.             if [[ "$i" == *key_22_$curd*.pub ]] && [ -r "$i" ] ; then
  2503.             host=${i/#*key_22_/}
  2504.             host=${host/%.pub/}
  2505.             COMPREPLY=( ${COMPREPLY[@]} $host )
  2506.             fi
  2507.         done
  2508.         fi
  2509.         # append any available aliases from config files
  2510.         if [ ${#config[@]} -gt 0 ] && [ -n "$aliases" ]; then
  2511.         hosts=$( compgen -W "$( sed -ne 's/^[Hh][Oo][Ss][Tt]['"$'\t '"']*\([^*?]*\)$/\1/p' ${config[@]} )" -- $ocur )
  2512.         COMPREPLY=( ${COMPREPLY[@]} $hosts )
  2513.         fi
  2514.  
  2515.         # apply suffix
  2516.         for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
  2517.         COMPREPLY[i]=$user${COMPREPLY[i]}$suffix
  2518.         done
  2519.     else
  2520.         # Just do normal hostname completion
  2521.         COMPREPLY=( $( compgen -A hostname -S "$suffix" -- $cur ) )
  2522.     fi
  2523.  
  2524.     return 0
  2525. }
  2526. complete -F _known_hosts traceroute traceroute6 tracepath tracepath6 \
  2527.     ping fping telnet host nslookup rsh rlogin ftp dig ssh-installkeys mtr
  2528.  
  2529. # ssh(1) completion
  2530. #
  2531. have ssh && {
  2532. _ssh()
  2533. {
  2534.     local cur prev
  2535.     local -a config
  2536.  
  2537.     COMPREPLY=()
  2538.     cur=${COMP_WORDS[COMP_CWORD]}
  2539.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2540.  
  2541.     case "$prev" in
  2542.     -*c)
  2543.         COMPREPLY=( $( compgen -W 'blowfish 3des 3des-cbc blowfish-cbc \
  2544.                arcfour cast128-cbc' -- $cur ) )
  2545.         ;;
  2546.     -*i)
  2547.         _filedir
  2548.         ;;
  2549.     -*l)
  2550.         COMPREPLY=( $( compgen -u -- $cur ) )
  2551.         ;;
  2552.     *)
  2553.         _known_hosts -a
  2554.  
  2555.         [ $COMP_CWORD -eq 1 ] || \
  2556.         COMPREPLY=( ${COMPREPLY[@]} $( compgen -c -- $cur ) )
  2557.     esac
  2558.  
  2559.     return 0
  2560. }
  2561. shopt -u hostcomplete && complete -F _ssh ssh slogin sftp xhost autossh
  2562.  
  2563. # scp(1) completion
  2564. #
  2565. _scp()
  2566. {
  2567.     local cur userhost path
  2568.  
  2569.     local IFS=$'\t\n'
  2570.     COMPREPLY=()
  2571.     cur=${COMP_WORDS[COMP_CWORD]}
  2572.  
  2573.     _expand || return 0
  2574.  
  2575.     if [[ "$cur" == *:* ]]; then
  2576.         # remove backslash escape from :
  2577.         cur=${cur/\\:/:}
  2578.         userhost=${cur%%?(\\):*}
  2579.         path=${cur#*:}
  2580.         # unescape spaces
  2581.         path=${path//\\\\\\\\ / }
  2582.         if [ -z "$path" ]; then
  2583.             # default to home dir of specified user on remote host
  2584.             path=$(ssh -o 'Batchmode yes' $userhost pwd 2>/dev/null)
  2585.         fi
  2586.         # escape spaces; remove executables, aliases, pipes and sockets;
  2587.         # add space at end of file names
  2588.         COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \
  2589.                    command ls -aF1d "$path*" 2>/dev/null | \
  2590.                    sed -e "s/[][(){}<>\",:;^&!$&=?\`|\\ ']/\\\\\\\\\\\\&/g" \
  2591.                    -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
  2592.         return 0
  2593.     fi
  2594.  
  2595.     [[ "$cur" == */* ]] || _known_hosts -c -a
  2596.         COMPREPLY=( ${COMPREPLY[@]} $( command ls -aF1d $cur* \
  2597.                 2>/dev/null | sed \
  2598.                 -e "s/[][(){}<>\",:;^&!$&=?\`|\\ ']/\\\\&/g" \
  2599.                 -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
  2600.     return 0
  2601. }
  2602. complete -F _scp $nospace scp
  2603. }
  2604.  
  2605. # rsync(1) completion
  2606. #
  2607. have rsync &&
  2608. _rsync()
  2609. {
  2610.     local cur prev shell i userhost path
  2611.  
  2612.     COMPREPLY=()
  2613.     cur=${COMP_WORDS[COMP_CWORD]}
  2614.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2615.  
  2616.     _expand || return 0
  2617.  
  2618.     case "$prev" in
  2619.     --@(config|password-file|include-from|exclude-from))
  2620.         _filedir
  2621.         return 0
  2622.         ;;
  2623.     -@(T|-temp-dir|-compare-dest))
  2624.         _filedir -d
  2625.         return 0
  2626.         ;;
  2627.     -@(e|-rsh))
  2628.         COMPREPLY=( $( compgen -W 'rsh ssh' -- $cur ) )
  2629.         return 0
  2630.         ;;
  2631.     esac
  2632.  
  2633.     case "$cur" in
  2634.     -*)
  2635.         COMPREPLY=( $( compgen -W '-v -q  -c -a -r -R -b -u -l -L -H \
  2636.                 -p -o -g -D -t -S -n -W -x -B -e -C -I -T -P \
  2637.                 -z -h -4 -6 --verbose --quiet --checksum \
  2638.                 --archive --recursive --relative --backup \
  2639.                 --backup-dir --suffix= --update --links \
  2640.                 --copy-links --copy-unsafe-links --safe-links \
  2641.                 --hard-links --perms --owner --group --devices\
  2642.                 --times --sparse --dry-run --whole-file \
  2643.                 --no-whole-file --one-file-system \
  2644.                 --block-size= --rsh= --rsync-path= \
  2645.                 --cvs-exclude --existing --ignore-existing \
  2646.                 --delete --delete-excluded --delete-after \
  2647.                 --ignore-errors --max-delete= --partial \
  2648.                 --force --numeric-ids --timeout= \
  2649.                 --ignore-times --size-only --modify-window= \
  2650.                 --temp-dir= --compare-dest= --compress \
  2651.                 --exclude= --exclude-from= --include= \
  2652.                 --include-from= --version --daemon --no-detach\
  2653.                 --address= --config= --port= --blocking-io \
  2654.                 --no-blocking-io --stats --progress \
  2655.                 --log-format= --password-file= --bwlimit= \
  2656.                 --write-batch= --read-batch= --help' -- $cur ))
  2657.         ;;
  2658.     *:*)
  2659.         # find which remote shell is used
  2660.         shell=rsh
  2661.         for (( i=1; i < COMP_CWORD; i++ )); do
  2662.             if [[ "${COMP_WORDS[i]}" == -@(e|-rsh) ]]; then
  2663.                 shell=${COMP_WORDS[i+1]}
  2664.                 break
  2665.             fi
  2666.         done
  2667.         if [[ "$shell" == ssh ]]; then
  2668.             # remove backslash escape from :
  2669.             cur=${cur/\\:/:}
  2670.             userhost=${cur%%?(\\):*}
  2671.             path=${cur#*:}
  2672.             # unescape spaces
  2673.             path=${path//\\\\\\\\ / }
  2674.             if [ -z "$path" ]; then
  2675.                 # default to home dir of specified
  2676.                 # user on remote host
  2677.                 path=$(ssh -o 'Batchmode yes' \
  2678.                     $userhost pwd 2>/dev/null)
  2679.             fi
  2680.             # escape spaces; remove executables, aliases, pipes
  2681.             # and sockets; add space at end of file names
  2682.             COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \
  2683.                 command ls -aF1d "$path*" 2>/dev/null | \
  2684.                 sed -e 's/ /\\\\\\\ /g' -e 's/[*@|=]$//g' \
  2685.                 -e 's/[^\/]$/& /g' ) )
  2686.         fi
  2687.         ;;
  2688.     *)
  2689.         _known_hosts -c -a
  2690.         _filedir
  2691.         ;;
  2692.     esac
  2693.  
  2694.     return 0
  2695. } &&
  2696. complete -F _rsync $nospace $filenames rsync
  2697.  
  2698. # Linux route(8) completion
  2699. #
  2700. [ $UNAME = Linux ] &&
  2701. _route()
  2702. {
  2703.     local cur prev
  2704.  
  2705.     COMPREPLY=()
  2706.     cur=${COMP_WORDS[COMP_CWORD]}
  2707.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2708.  
  2709.     if [ "$prev" = dev ]; then
  2710.         COMPREPLY=( $( ifconfig -a | sed -ne 's|^\('$cur'[^ ]*\).*$|\1|p' ))
  2711.         return 0
  2712.     fi
  2713.  
  2714.     COMPREPLY=( $( compgen -W 'add del -host -net netmask metric mss \
  2715.                    window irtt reject mod dyn reinstate dev \
  2716.                    default gw' -- $cur ) )
  2717.  
  2718.     COMPREPLY=( $( echo " ${COMP_WORDS[@]}" | \
  2719.                (while read -d ' ' i; do
  2720.                [ "$i" == "" ] && continue
  2721.                # flatten array with spaces on either side,
  2722.                # otherwise we cannot grep on word
  2723.                # boundaries of first and last word
  2724.                COMPREPLY=" ${COMPREPLY[@]} "
  2725.                # remove word from list of completions
  2726.                COMPREPLY=( ${COMPREPLY/ $i / } )
  2727.             done
  2728.                echo ${COMPREPLY[@]})
  2729.           ) )
  2730.     return 0
  2731. }
  2732. [ $UNAME = Linux ] && complete -F _route route
  2733.  
  2734. # GNU make(1) completion
  2735. #
  2736. have make || have gmake || have gnumake || have pmake &&
  2737. _make()
  2738. {
  2739.     local file makef makef_dir="." makef_inc cur prev i
  2740.  
  2741.     COMPREPLY=()
  2742.     cur=${COMP_WORDS[COMP_CWORD]}
  2743.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2744.  
  2745.     # --name value style option
  2746.     case $prev in
  2747.         -@(f|o|W))
  2748.             _filedir
  2749.             return 0
  2750.             ;;
  2751.         -@(I|C))
  2752.             _filedir -d
  2753.             return 0
  2754.             ;;
  2755.     esac
  2756.  
  2757.     # --name=value style option
  2758.     if [[ "$cur" == *=* ]]; then
  2759.         prev=${cur/=*/}
  2760.         cur=${cur/*=/}
  2761.         case "$prev" in
  2762.             --@(file|makefile))
  2763.                 _filedir
  2764.                 return 0
  2765.                 ;;
  2766.             --@(directory|include-dir))
  2767.                 _filedir -d
  2768.                 return 0
  2769.                 ;;
  2770.         esac
  2771.     fi
  2772.  
  2773.     if [[ "$cur" == -* ]]; then
  2774.         COMPREPLY=( $( compgen -W '-b -m -B -C -d -e -f -h -i -I\
  2775.             -j -l -k -n -o -p -q -r -R - s -S -t -v -w -W \
  2776.             --always-make --directory= --debug \
  2777.             --environment-overrides --file= --makefile= --help \
  2778.             --ignore-errors --include-dir= --jobs --load-average \
  2779.             --max-load --keep-going --just-print --dry-run \
  2780.             --recon --old-file= --assume-old= --print-data-base \
  2781.             --question --no-builtin-rules --no-builtin-variables \
  2782.             --silent --quiet --no-keep-goind --stop --touch \
  2783.             --version --print-directory --no-print-directory \
  2784.             --what-if= --new-file= --assume-new= \
  2785.             --warn-undefined-variables' -- $cur ) )
  2786.     else
  2787.         # before we check for makefiles, see if a path was specified
  2788.         # with -C
  2789.         for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
  2790.             if [[ ${COMP_WORDS[i]} == -C ]]; then
  2791.                 # eval for tilde expansion
  2792.                 eval makef_dir=${COMP_WORDS[i+1]}
  2793.                 break
  2794.             fi
  2795.         done
  2796.  
  2797.         # make reads `GNUmakefile', then `makefile', then `Makefile'
  2798.         if [ -f ${makef_dir}/GNUmakefile ]; then
  2799.             makef=${makef_dir}/GNUmakefile
  2800.         elif [ -f ${makef_dir}/makefile ]; then
  2801.             makef=${makef_dir}/makefile
  2802.         elif [ -f ${makef_dir}/Makefile ]; then
  2803.             makef=${makef_dir}/Makefile
  2804.         else
  2805.             makef=${makef_dir}/*.mk           # local convention
  2806.         fi
  2807.  
  2808.         # before we scan for targets, see if a Makefile name was
  2809.         # specified with -f
  2810.         for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
  2811.             if [[ ${COMP_WORDS[i]} == -f ]]; then
  2812.                 # eval for tilde expansion
  2813.                 eval makef=${COMP_WORDS[i+1]}
  2814.                 break
  2815.             fi
  2816.         done
  2817.  
  2818.         [ ! -f $makef ] && return 0
  2819.  
  2820.         # deal with included Makefiles
  2821.          makef_inc=$( grep -E '^-?include' $makef | sed -e "s,^.* ,"$makef_dir"/," )
  2822.  
  2823.          for file in $makef_inc; do
  2824.              [ -f $file ] && makef="$makef $file"
  2825.          done
  2826.  
  2827.         COMPREPLY=( $( awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ \
  2828.                 {split($1,A,/ /);for(i in A)print A[i]}' \
  2829.                 $makef 2>/dev/null | command grep "^$cur" ))
  2830.     fi
  2831. } &&
  2832. complete -f -F _make $filenames make gmake gnumake pmake
  2833.  
  2834. # GNU tar(1) completion
  2835. #
  2836. _tar()
  2837. {
  2838.     local cur ext regex tar untar
  2839.  
  2840.     COMPREPLY=()
  2841.     cur=${COMP_WORDS[COMP_CWORD]}
  2842.  
  2843.     if [ $COMP_CWORD -eq 1 ]; then
  2844.         COMPREPLY=( $( compgen -W 'c t x u r d A' -- $cur ) )
  2845.         return 0
  2846.     fi
  2847.  
  2848.     case "${COMP_WORDS[1]}" in
  2849.     ?(-)c*f)
  2850.         _filedir
  2851.         return 0
  2852.         ;;
  2853.     +([^IZzjy])f)
  2854.         ext='t@(ar?(.@(Z|gz|bz?(2)))|gz|bz?(2))'
  2855.         regex='t\(ar\(\.\(Z\|gz\|bz2\?\)\)\?\|gz\|bz2\?\)'
  2856.         ;;
  2857.     *[Zz]*f)
  2858.         ext='t?(ar.)@(gz|Z)'
  2859.         regex='t\(ar\.\)\?\(gz\|Z\)'
  2860.         ;;
  2861.     *[Ijy]*f)
  2862.         ext='t?(ar.)bz?(2)'
  2863.         regex='t\(ar\.\)\?bz2\?'
  2864.         ;;
  2865.     *)
  2866.         _filedir
  2867.         return 0
  2868.         ;;
  2869.         
  2870.     esac
  2871.  
  2872.     if [[ "$COMP_LINE" == *$ext' ' ]]; then
  2873.         # complete on files in tar file
  2874.         #
  2875.         # get name of tar file from command line
  2876.         tar=$( echo "$COMP_LINE" | \
  2877.             sed -e 's/^.* \([^ ]*'$regex'\) .*$/\1/' )
  2878.         # devise how to untar and list it
  2879.         untar=t${COMP_WORDS[1]//[^Izjyf]/}
  2880.  
  2881.         COMPREPLY=( $( compgen -W "$( echo $( tar $untar $tar \
  2882.                 2>/dev/null ) )" -- "$cur" ) )
  2883.         return 0
  2884.     fi
  2885.  
  2886.     # file completion on relevant files
  2887.     _filedir $ext
  2888.  
  2889.     return 0
  2890. }
  2891. [ -n "${COMP_TAR_INTERNAL_PATHS:-}" ] && complete -F _tar $dirnames tar ||
  2892.     complete -F _tar $filenames tar
  2893.  
  2894. # jar(1) completion
  2895. #
  2896. have jar &&
  2897. _jar()
  2898. {
  2899.     local cur
  2900.  
  2901.     COMPREPLY=()
  2902.     cur=${COMP_WORDS[COMP_CWORD]}
  2903.  
  2904.     if [ $COMP_CWORD = 1 ]; then
  2905.         COMPREPLY=( $( compgen -W 'c t x u' -- $cur ) )
  2906.         return 0
  2907.     fi
  2908.  
  2909.     case "${COMP_WORDS[1]}" in
  2910.         *c*f)
  2911.             _filedir
  2912.             ;;
  2913.         *f)
  2914.             _filedir '?(e|j|w)ar'
  2915.             ;;
  2916.         *)
  2917.             _filedir
  2918.             ;;
  2919.     esac
  2920. } &&
  2921. complete -F _jar $filenames jar
  2922.  
  2923. # Linux iptables(8) completion
  2924. #
  2925. have iptables &&
  2926. _iptables()
  2927. {
  2928.     local cur prev table chain
  2929.  
  2930.     COMPREPLY=()
  2931.     cur=${COMP_WORDS[COMP_CWORD]} 
  2932.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2933.     chain='s/^Chain \([^ ]\+\).*$/\1/p'
  2934.  
  2935.     if [[ $COMP_LINE == *-t\ *filter* ]]; then
  2936.         table="-t filter"
  2937.     elif [[ $COMP_LINE == *-t\ *nat* ]]; then
  2938.         table="-t nat"
  2939.     elif [[ $COMP_LINE == *-t\ *mangle* ]]; then
  2940.         table="-t mangle"
  2941.     fi
  2942.  
  2943.     case "$prev" in
  2944.     -*[AIDRPFXLZ])
  2945.         COMPREPLY=( $( compgen -W '`iptables $table -nL | \
  2946.                 sed -ne "s/^Chain \([^ ]\+\).*$/\1/p"`' -- $cur ) )
  2947.         ;;
  2948.     -*t)
  2949.         COMPREPLY=( $( compgen -W 'nat filter mangle' -- $cur ) )
  2950.         ;;
  2951.     -j)
  2952.         if [ "$table" = "-t filter" -o "$table" = "" ]; then
  2953.             COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \
  2954.             `iptables $table -nL | sed -ne "$chain" \
  2955.             -e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \
  2956.             $cur ) )
  2957.         elif [ "$table" = "-t nat" ]; then
  2958.             COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \
  2959.             MIRROR SNAT DNAT MASQUERADE `iptables $table -nL | \
  2960.             sed -ne "$chain" -e "s/OUTPUT|PREROUTING|POSTROUTING//"`' \
  2961.             -- $cur ) )
  2962.         elif [ "$table" = "-t mangle" ]; then
  2963.             COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \
  2964.             MARK TOS `iptables $table -nL | sed -ne "$chain" \
  2965.             -e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \
  2966.             $cur ) )
  2967.         fi
  2968.         ;;
  2969.     *)
  2970.         if [[ "$cur" == -* ]]; then
  2971.             COMPREPLY=( $( compgen -W '-i -o -s -d -p -f -m --append \
  2972.             --delete --insert --replace --list --flush --zero --new \
  2973.             --delete-chain --policy --rename-chain --proto --source \
  2974.             --destination --in-interface --jump --match --numeric \
  2975.             --out-interface --table --verbose --line-numbers --exact \
  2976.             --fragment --modprobe= --set-counters --version' -- "$cur") )
  2977.         fi
  2978.         ;;
  2979.     esac
  2980.  
  2981. } &&
  2982. complete -F _iptables iptables
  2983.  
  2984. # tcpdump(8) completion
  2985. #
  2986. have tcpdump &&
  2987. _tcpdump()
  2988. {
  2989.     local cur
  2990.  
  2991.     COMPREPLY=()
  2992.     cur=${COMP_WORDS[COMP_CWORD]}
  2993.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2994.  
  2995.     case "$prev" in
  2996.         -@(r|w|F))
  2997.             _filedir
  2998.             return 0
  2999.             ;;
  3000.         -i)
  3001.             _available_interfaces -a
  3002.             return 0
  3003.             ;;
  3004.     esac
  3005.  
  3006.  
  3007.     if [[ "$cur" == -* ]]; then
  3008.         COMPREPLY=( $( compgen -W '-a -d -e -f -l -n -N -O -p \
  3009.             -q -R -S -t -u -v -x -C -F -i -m -r -s -T -w \
  3010.             -E' -- $cur ) )
  3011.     fi
  3012.  
  3013. } &&
  3014. complete -F _tcpdump tcpdump
  3015.  
  3016. # autorpm(8) completion
  3017. #
  3018. have autorpm &&
  3019. _autorpm()
  3020. {
  3021.     local cur
  3022.  
  3023.     COMPREPLY=()
  3024.     cur=${COMP_WORDS[COMP_CWORD]}
  3025.  
  3026.     COMPREPLY=( $( compgen -W '--notty --debug --help --version \
  3027.                    auto add fullinfo info help install list \
  3028.                    remove set' -- $cur ) )
  3029.  
  3030. } &&
  3031. complete -F _autorpm autorpm
  3032.  
  3033. # This meta-cd function observes the CDPATH variable, so that cd additionally
  3034. # completes on directories under those specified in CDPATH.
  3035. #
  3036. _cd()
  3037. {
  3038.     local IFS=$'\t\n' cur=${COMP_WORDS[COMP_CWORD]} i j k
  3039.  
  3040.     # try to allow variable completion
  3041.     if [[ "$cur" == ?(\\)\$* ]]; then
  3042.         COMPREPLY=( $( compgen -v -P '$' -- "${cur#?(\\)$}" ) )
  3043.         return 0
  3044.     fi
  3045.  
  3046.     # Use standard dir completion if no CDPATH or parameter starts with /,
  3047.     # ./ or ../
  3048.     if [ -z "${CDPATH:-}" ] || [[ "$cur" == ?(.)?(.)/* ]]; then
  3049.         _filedir -d
  3050.         return 0
  3051.     fi
  3052.  
  3053.     local -r mark_dirs=$(_rl_enabled mark-directories && echo y)
  3054.     local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y)
  3055.  
  3056.     # we have a CDPATH, so loop on its contents
  3057.     for i in ${CDPATH//:/$'\t'}; do
  3058.         # create an array of matched subdirs
  3059.         k=${#COMPREPLY[@]}
  3060.         for j in $( compgen -d $i/$cur ); do
  3061.             if [[ ( $mark_symdirs && -h $j || $mark_dirs && ! -h $j ) && ! -d ${j#$i/} ]]; then
  3062.                 j="${j}/"
  3063.             fi
  3064.             COMPREPLY[k++]=${j#$i/}
  3065.         done
  3066.     done
  3067.  
  3068.     _filedir -d
  3069.  
  3070.     if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
  3071.         i=${COMPREPLY[0]}
  3072.         if [ "$i" == "$cur" ] && [[ $i != "*/" ]]; then
  3073.         COMPREPLY[0]="${i}/"
  3074.         fi
  3075.     fi
  3076.         
  3077.     return 0
  3078. }
  3079. if shopt -q cdable_vars; then
  3080.     complete -v -F _cd $nospace $filenames cd
  3081. else
  3082.     complete -F _cd $nospace $filenames cd
  3083. fi
  3084.  
  3085. # A meta-command completion function for commands like sudo(8), which need to
  3086. # first complete on a command, then complete according to that command's own
  3087. # completion definition - currently not quite foolproof (e.g. mount and umount
  3088. # don't work properly), but still quite useful.
  3089. #
  3090. _command()
  3091. {
  3092.     local cur func cline cspec noglob cmd done i \
  3093.           _COMMAND_FUNC _COMMAND_FUNC_ARGS
  3094.  
  3095.     COMPREPLY=()
  3096.     cur=${COMP_WORDS[COMP_CWORD]}
  3097.     # If the the first arguments following our meta-command-invoker are
  3098.     # switches, get rid of them. Most definitely not foolproof.
  3099.     done=
  3100.     while [ -z $done ] ; do
  3101.     cmd=${COMP_WORDS[1]}
  3102.         if [[ "$cmd" == -* ]] ; then
  3103.         for (( i=1 ; i<=COMP_CWORD ; i++)) ; do
  3104.             COMP_WORDS[i]=${COMP_WORDS[i+1]}
  3105.         done
  3106.         COMP_CWORD=$(($COMP_CWORD-1))
  3107.         else 
  3108.         done=1
  3109.         fi
  3110.     done
  3111.  
  3112.     if [ $COMP_CWORD -eq 1 ]; then
  3113.         COMPREPLY=( $( compgen -c -- $cur ) )
  3114.     elif complete -p $cmd &>/dev/null; then
  3115.         cspec=$( complete -p $cmd )
  3116.         if [ "${cspec#* -F }" != "$cspec" ]; then
  3117.             # complete -F <function>
  3118.             #
  3119.             # COMP_CWORD and COMP_WORDS() are not read-only,
  3120.             # so we can set them before handing off to regular
  3121.             # completion routine
  3122.  
  3123.             # set current token number to 1 less than now
  3124.             COMP_CWORD=$(( $COMP_CWORD - 1 ))
  3125.  
  3126.             # get function name
  3127.             func=${cspec#*-F }
  3128.             func=${func%% *}
  3129.             # get current command line minus initial command
  3130.             cline="${COMP_LINE#*( )$1 }"
  3131.             # save noglob state
  3132.                   shopt -qo noglob; noglob=$?
  3133.             # turn on noglob, as things like 'sudo ls *<Tab>'
  3134.             # don't work otherwise
  3135.               shopt -so noglob
  3136.             # split current command line tokens into array
  3137.             COMP_WORDS=( $cline )
  3138.             # reset noglob if necessary
  3139.             [ $noglob -eq 1 ] && shopt -uo noglob
  3140.             $func $cline
  3141.             # This is needed in case user finished entering
  3142.             # command and pressed tab (e.g. sudo ls <Tab>)
  3143.             COMP_CWORD=$(( $COMP_CWORD > 0 ? $COMP_CWORD : 1 ))
  3144.             cur=${COMP_WORDS[COMP_CWORD]}
  3145.             _COMMAND_FUNC=$func
  3146.             _COMMAND_FUNC_ARGS=( $cmd $2 $3 )
  3147.             COMP_LINE=$cline
  3148.             COMP_POINT=$(( ${COMP_POINT} - ${#1} - 1 ))
  3149.             $func $cmd $2 $3
  3150.             # remove any \: generated by a command that doesn't
  3151.             # default to filenames or dirnames (e.g. sudo chown)
  3152.             if [ "${cspec#*-o }" != "$cspec" ]; then
  3153.                 cspec=${cspec#*-o }
  3154.                 cspec=${cspec%% *}
  3155.                 if [[ "$cspec" != @(dir|file)names ]]; then
  3156.                     COMPREPLY=("${COMPREPLY[@]//\\\\:/:}")
  3157.                 fi
  3158.             fi
  3159.         elif [ -n "$cspec" ]; then
  3160.             cspec=${cspec#complete};
  3161.             cspec=${cspec%%$cmd};
  3162.             COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) );
  3163.         fi
  3164.     fi
  3165.  
  3166.     [ ${#COMPREPLY[@]} -eq 0 ] && _filedir
  3167. }
  3168. complete -F _command $filenames nohup exec nice eval strace time ltrace then \
  3169.     else do vsound command xargs
  3170.  
  3171. _root_command()
  3172. {
  3173.     PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin _command $1 $2 $3
  3174. }
  3175. complete -F _root_command $filenames sudo fakeroot really
  3176.  
  3177. # ant(1) completion
  3178. #
  3179. have ant && {
  3180. _ant()
  3181. {
  3182.     local cur prev buildfile i
  3183.  
  3184.     COMPREPLY=()
  3185.     cur=${COMP_WORDS[COMP_CWORD]}
  3186.     prev=${COMP_WORDS[COMP_CWORD-1]}
  3187.  
  3188.     case "$prev" in
  3189.         -buildfile|-f)
  3190.             _filedir 'xml'
  3191.             return 0
  3192.             ;;
  3193.         -logfile)
  3194.             _filedir
  3195.             return 0
  3196.             ;;
  3197.     esac
  3198.  
  3199.     if [[ "$cur" == -* ]]; then
  3200.         # relevant options completion
  3201.         COMPREPLY=( $( compgen -W '-help -projecthelp -version -quiet \
  3202.                    -verbose -debug -emacs -logfile -logger \
  3203.                    -listener -buildfile -f -D -find' -- $cur ) )
  3204.     else
  3205.         # available targets completion
  3206.         # find which buildfile to use
  3207.         buildfile=build.xml
  3208.         for (( i=1; i < COMP_CWORD; i++ )); do
  3209.             if [[ "${COMP_WORDS[i]}" == -buildfile ]]; then
  3210.                 buildfile=${COMP_WORDS[i+1]}
  3211.                 break
  3212.             fi
  3213.         done
  3214.         [ ! -f $buildfile ] && return 0
  3215.  
  3216.         # parse buildfile for targets
  3217.         COMPREPLY=( $( awk -F'"' '/<target name="/ {print $2}' \
  3218.                 $buildfile | grep "^$cur" )
  3219.                 $( awk -F"'" "/<target name='/ "'{print $2}' \
  3220.                 $buildfile | grep "^$cur" )
  3221.                 $( awk -F'"' '/<target [^n]/ {if ($1 ~ /name=/) { print $2 } else if ($3 ~ /name=/) {print $4} else if ($5 ~ /name=/) {print $6}}' \
  3222.                 $buildfile | grep "^$cur" ) )
  3223.     fi
  3224. }
  3225. have complete-ant-cmd.pl && \
  3226.      complete -C complete-ant-cmd.pl -F _ant $filenames ant || \
  3227.      complete -F _ant $filenames ant
  3228. }
  3229.  
  3230. have nslookup &&
  3231. _nslookup()
  3232. {
  3233.     local cur
  3234.  
  3235.     COMPREPLY=()
  3236.     cur=${COMP_WORDS[COMP_CWORD]#-}
  3237.  
  3238.     COMPREPLY=( $( compgen -P '-' -W 'all class= debug d2 domain= \
  3239.                    srchlist= defname search port= querytype= \
  3240.                    type= recurse retry root timeout vc \
  3241.                    ignoretc' -- $cur ) )
  3242. } &&
  3243. complete -F _nslookup nslookup
  3244.  
  3245. # mysqladmin(1) completion
  3246. #
  3247. have mysqladmin &&
  3248. _mysqladmin()
  3249. {
  3250.     local cur prev
  3251.  
  3252.     COMPREPLY=()
  3253.     cur=${COMP_WORDS[COMP_CWORD]} 
  3254.     prev=${COMP_WORDS[COMP_CWORD-1]}
  3255.  
  3256.     case "$prev" in
  3257.     -u)
  3258.         COMPREPLY=( $( compgen -u -- $cur ) )
  3259.         return 0
  3260.         ;;
  3261.     *)
  3262.         ;;
  3263.     esac
  3264.  
  3265.     COMPREPLY=( $( compgen -W '-# -f -? -C -h -p -P -i -r -E -s -S -t -u \
  3266.                           -v -V -w' -- $cur ) )
  3267.  
  3268.     COMPREPLY=( ${COMPREPLY[@]} \
  3269.             $( compgen -W 'create drop extended-status flush-hosts \
  3270.                    flush-logs flush-status flush-tables \
  3271.                    flush-threads flush-privileges kill \
  3272.                    password ping processlist reload refresh \
  3273.                    shutdown status variables version' \
  3274.                -- $cur ) )
  3275. } &&
  3276. complete -F _mysqladmin mysqladmin
  3277.  
  3278. # gzip(1) completion
  3279. #
  3280. have gzip &&
  3281. _gzip()
  3282. {
  3283.     local cur prev xspec IFS=$'\t\n'
  3284.  
  3285.     COMPREPLY=()
  3286.     cur=${COMP_WORDS[COMP_CWORD]}
  3287.     prev=${COMP_WORDS[COMP_CWORD-1]}
  3288.  
  3289.     if [[ "$cur" == -* ]]; then
  3290.         COMPREPLY=( $( compgen -W '-c -d -f \
  3291.             -h -l -L -n -N -q -r -S -t -v -V \
  3292.             -1 -2 -3 -4 -5 -6 -7 -8 -9 \
  3293.             --stdout --decompress --force --help --list \
  3294.             --license --no-name --name --quiet --recursive \
  3295.             --suffix --test --verbose --version --fast \
  3296.             --best' -- $cur ) )
  3297.         return 0
  3298.     fi
  3299.  
  3300.     xspec="*.?(t)gz"
  3301.     if [[ "$prev" == --* ]]; then
  3302.         [[ "$prev" == --decompress || \
  3303.             "$prev" == --list || \
  3304.             "$prev" == --test ]] && xspec="!"$xspec
  3305.         [[ "$prev" == --force ]] && xspec=
  3306.     elif [[ "$prev" == -* ]]; then
  3307.         [[ "$prev" == -*[dlt]* ]] && xspec="!"$xspec
  3308.         [[ "$prev" == -*f* ]] && xspec=
  3309.     elif [ "$prev" = '>' ]; then
  3310.         xspec=
  3311.     fi
  3312.  
  3313.     _expand || return 0
  3314.  
  3315.     COMPREPLY=( $( compgen -f -X "$xspec" -- $cur ) \
  3316.             $( compgen -d -- $cur ) )
  3317. } &&
  3318. complete -F _gzip $filenames gzip
  3319.  
  3320. # bzip2(1) completion
  3321. #
  3322. have bzip2 &&
  3323. _bzip2()
  3324. {
  3325.     local cur prev xspec IFS=$'\t\n'
  3326.  
  3327.     COMPREPLY=()
  3328.     cur=${COMP_WORDS[COMP_CWORD]}
  3329.     prev=${COMP_WORDS[COMP_CWORD-1]}
  3330.  
  3331.     if [[ "$cur" == -* ]]; then
  3332.         COMPREPLY=( $( compgen -W '-c -d -f -h -k -L -q -s \
  3333.             -t -v -V -z -1 -2 -3 -4 -5 -6 -7 -8 -9 \
  3334.             --help --decompress --compress --keep --force \
  3335.             --test --stdout --quiet --verbose --license \
  3336.             --version --small --fast --best' -- $cur ) )
  3337.         return 0
  3338.     fi
  3339.  
  3340.     xspec="*.bz2"
  3341.     if [[ "$prev" == --* ]]; then
  3342.         [[ "$prev" == --decompress || \
  3343.             "$prev" == --list || \
  3344.             "$prev" == --test ]] && xspec="!"$xspec
  3345.         [[ "$prev" == --compress ]] && xspec=
  3346.     elif [[ "$prev" == -* ]]; then
  3347.         [[ "$prev" == -*[dt]* ]] && xspec="!"$xspec
  3348.         [[ "$prev" == -*z* ]] && xspec=
  3349.     fi
  3350.  
  3351.     _expand || return 0
  3352.  
  3353.     COMPREPLY=( $( compgen -f -X "$xspec" -- $cur ) \
  3354.             $( compgen -d -- $cur ) )
  3355. } &&
  3356. complete -F _bzip2 $filenames bzip2
  3357.  
  3358. # openssl(1) completion
  3359. #
  3360. have openssl && {
  3361. _openssl_sections()
  3362. {
  3363.     local config
  3364.  
  3365.     config=/etc/ssl/openssl.cnf
  3366.     [ ! -f $config ] && config=/usr/share/ssl/openssl.cnf
  3367.     for (( i=2; i < COMP_CWORD; i++ )); do
  3368.         if [[ "${COMP_WORDS[i]}" == -config ]]; then
  3369.             config=${COMP_WORDS[i+1]}
  3370.             break
  3371.         fi
  3372.     done
  3373.     [ ! -f $config ] && return 0
  3374.  
  3375.     COMPREPLY=( $( awk '/\[.*\]/ {print $2} ' $config | grep "^$cur" ) )
  3376. }
  3377.  
  3378. _openssl()
  3379. {
  3380.     local cur prev
  3381.  
  3382.     COMPREPLY=()
  3383.     cur=${COMP_WORDS[COMP_CWORD]}
  3384.  
  3385.     if [ $COMP_CWORD -eq 1 ]; then
  3386.         COMPREPLY=( $( compgen -W 'asn1parse ca ciphers crl crl2pkcs7 \
  3387.             dgst dh dhparam dsa dsaparam enc errstr gendh gendsa \
  3388.             genrsa nseq passwd pkcs12 pkcs7 pkcs8 rand req rsa \
  3389.             rsautl s_client s_server s_time sess_id smime speed \
  3390.             spkac verify version x509 md2 md4 md5 mdc2 rmd160 sha \
  3391.             sha1 base64 bf bf-cbc bf-cfb bf-ecb bf-ofb cast \
  3392.             cast-cbc cast5-cbc cast5-cfb cast5-ecb cast5-ofb des \
  3393.             des-cbc des-cfb des-ecb des-ede des-ede-cbc \
  3394.             des-ede-cfb des-ede-ofb des-ede3 des-ede3-cbc \
  3395.             des-ede3-cfb des-ede3-ofb des-ofb des3 desx rc2 \
  3396.             rc2-40-cbc rc2-64-cbc rc2-cbc rc2-cfb rc2-ecb rc2-ofb \
  3397.             rc4 rc4-40' -- $cur ) )
  3398.     else
  3399.         prev=${COMP_WORDS[COMP_CWORD-1]}
  3400.         case ${COMP_WORDS[1]} in
  3401.             asn1parse)
  3402.                 case $prev in
  3403.                     -inform)
  3404.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3405.                         return 0
  3406.                         ;;
  3407.                     -@(in|out|oid))
  3408.                         _filedir
  3409.                         return 0
  3410.                         ;;
  3411.                     esac
  3412.  
  3413.                 if [[ "$cur" == -* ]]; then
  3414.                     COMPREPLY=( $( compgen -W '-inform -in -out -noout -offset \
  3415.                         -length -i -oid -strparse' -- $cur ) )
  3416.                 fi
  3417.                 ;;
  3418.             ca)
  3419.                 case $prev in
  3420.                     -@(config|revoke|cert|in|out|spkac|ss_cert))
  3421.                         _filedir
  3422.                         return 0
  3423.                         ;;
  3424.                     -outdir)
  3425.                         _filedir -d
  3426.                         return 0
  3427.                         ;;
  3428.                     -@(name|crlexts|extensions))
  3429.                         _openssl_sections
  3430.                         return 0
  3431.                         ;;
  3432.                 esac
  3433.  
  3434.                 if [[ "$cur" == -* ]]; then
  3435.                     COMPREPLY=( $( compgen -W '-verbose -config -name \
  3436.                         -gencrl -revoke -crldays -crlhours -crlexts \
  3437.                         -startdate -enddate -days -md -policy -keyfile \
  3438.                         -key -passin -cert -in -out -notext -outdir \
  3439.                         -infiles -spkac -ss_cert -preserveDN -batch \
  3440.                         -msie_hack -extensions' -- $cur ) )
  3441.                 fi
  3442.                 ;;
  3443.             ciphers)
  3444.                 if [[ "$cur" == -* ]]; then
  3445.                     COMPREPLY=( $( compgen -W '-v -ssl2 -ssl3 -tls1' -- $cur ) )
  3446.                 fi
  3447.                 ;;
  3448.             crl)
  3449.                 case $prev in
  3450.                     -@(in|out)form)
  3451.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3452.                         return 0
  3453.                         ;;
  3454.                     -@(in|out|CAfile))
  3455.                         _filedir
  3456.                         return 0
  3457.                         ;;
  3458.                     -CAPath)
  3459.                         _filedir -d
  3460.                         return 0
  3461.                         ;;
  3462.                 esac
  3463.  
  3464.                 if [[ "$cur" == -* ]]; then
  3465.                     COMPREPLY=( $( compgen -W '-inform -outform -text -in -out -noout \
  3466.                         -hash -issuer -lastupdate -nextupdate -CAfile -CApath' -- $cur ) )
  3467.                 fi
  3468.                 ;;
  3469.             crl2pkcs7)
  3470.                 case $prev in
  3471.                     -@(in|out)form)
  3472.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3473.                         return 0
  3474.                         ;;
  3475.                     -@(in|out))
  3476.                         _filedir
  3477.                         return 0
  3478.                         ;;
  3479.                 esac
  3480.  
  3481.                 if [[ "$cur" == -* ]]; then
  3482.                     COMPREPLY=( $( compgen -W '-inform -outform -in -out -print_certs' -- $cur ) )
  3483.                 fi
  3484.                 ;;
  3485.             dgst)
  3486.                 case $prev in
  3487.                     -@(out|sign|verify|prvrify|signature))
  3488.                         _filedir
  3489.                         return 0
  3490.                         ;;
  3491.                 esac
  3492.  
  3493.                 if [[ "$cur" == -* ]]; then
  3494.                     COMPREPLY=( $( compgen -W '-md5 -md4 -md2 -sha1 -sha -mdc2 -ripemd160 -dss1 \
  3495.                         -c -d -hex -binary -out -sign -verify -prverify -signature' -- $cur ) )
  3496.                 else
  3497.                         _filedir
  3498.                 fi
  3499.                    ;;
  3500.             dsa)
  3501.                 case $prev in
  3502.                     -@(in|out)form)
  3503.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3504.                         return 0
  3505.                         ;;
  3506.                     -@(in|out))
  3507.                         _filedir
  3508.                         return 0
  3509.                         ;;
  3510.                 esac
  3511.  
  3512.                 if [[ "$cur" == -* ]]; then
  3513.                     COMPREPLY=( $( compgen -W '-inform -outform -in -passin -out -passout -des -des3 -idea -text -noout \
  3514.                         -modulus -pubin -pubout' -- $cur ) )
  3515.                 fi
  3516.                 ;;
  3517.             dsaparam)
  3518.                 case $prev in
  3519.                     -@(in|out)form)
  3520.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3521.                         return 0
  3522.                         ;;
  3523.                     -@(in|out|rand))
  3524.                         _filedir
  3525.                         return 0
  3526.                         ;;
  3527.                 esac
  3528.  
  3529.                 if [[ "$cur" == -* ]]; then
  3530.                     COMPREPLY=( $( compgen -W '-inform -outform -in -out -noout \
  3531.                         -text -C -rand -genkey' -- $cur ) )
  3532.                 fi
  3533.                 ;;
  3534.             enc)
  3535.                 case $prev in
  3536.                     -@(in|out|kfile))
  3537.                         _filedir
  3538.                         return 0
  3539.                         ;;
  3540.                 esac
  3541.  
  3542.                 if [[ "$cur" == -* ]]; then
  3543.                     COMPREPLY=( $( compgen -W '-ciphername -in -out -pass \
  3544.                         -e -d -a -A -k -kfile -S -K -iv -p -P -bufsize -debug' -- $cur ) )
  3545.                 fi
  3546.                 ;;
  3547.             dhparam)
  3548.                 case $prev in
  3549.                     -@(in|out)form)
  3550.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3551.                         return 0
  3552.                         ;;
  3553.                     -@(in|out|rand))
  3554.                         _filedir
  3555.                         return 0
  3556.                         ;;
  3557.                 esac
  3558.  
  3559.                 if [[ "$cur" == -* ]]; then
  3560.                     COMPREPLY=( $( compgen -W '-inform -outform -in -out -dsaparam -noout \
  3561.                         -text -C -2 -5 -rand' -- $cur ) )
  3562.                 fi
  3563.                 ;;
  3564.             gendsa)
  3565.                 case $prev in
  3566.                     -@(out|rand))
  3567.                         _filedir
  3568.                         return 0
  3569.                         ;;
  3570.                 esac
  3571.  
  3572.                 if [[ "$cur" == -* ]]; then
  3573.                     COMPREPLY=( $( compgen -W '-out -des -des3 -idea -rand' -- $cur ) )
  3574.                 else
  3575.                         _filedir
  3576.                 fi
  3577.                 ;;
  3578.             genrsa)
  3579.                 case $prev in
  3580.                     -@(out|rand))
  3581.                         _filedir
  3582.                         return 0
  3583.                         ;;
  3584.                 esac
  3585.  
  3586.                 if [[ "$cur" == -* ]]; then
  3587.                     COMPREPLY=( $( compgen -W '-out -passout -des -des3 -idea -f4 -3 -rand' -- $cur ) )
  3588.                 fi
  3589.                 ;;
  3590.             pkcs7)
  3591.                 case $prev in
  3592.                     -@(in|out)form)
  3593.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3594.                         return 0
  3595.                         ;;
  3596.                     -@(in|out))
  3597.                         _filedir
  3598.                         return 0
  3599.                         ;;
  3600.                 esac
  3601.  
  3602.                 if [[ "$cur" == -* ]]; then
  3603.                     COMPREPLY=( $( compgen -W '-inform -outform -in -out -print_certs -text -noout' -- $cur ) )
  3604.                 fi
  3605.                 ;;
  3606.             rand)
  3607.                 case $prev in
  3608.                     -@(out|rand))
  3609.                         _filedir
  3610.                         return 0
  3611.                         ;;
  3612.                 esac
  3613.  
  3614.                 if [[ "$cur" == -* ]]; then
  3615.                     COMPREPLY=( $( compgen -W '-out -rand -base64' -- $cur ) )
  3616.                 fi
  3617.                 ;;
  3618.             req)
  3619.                 case "$prev" in
  3620.                     -@(in|out|key)form)
  3621.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3622.                         return 0
  3623.                         ;;
  3624.  
  3625.                     -@(in|out|rand|key|keyout|config))
  3626.                         _filedir
  3627.                         return 0
  3628.                         ;;
  3629.                     -extensions)
  3630.                         _openssl_sections
  3631.                         return 0
  3632.                         ;;
  3633.                 esac
  3634.  
  3635.                 if [[ "$cur" == -* ]]; then
  3636.                     COMPREPLY=( $( compgen -W '-inform -outform -in \
  3637.                         -passin -out -passout -text -noout -verify \
  3638.                         -modulus -new -rand -newkey -newkey -nodes \
  3639.                         -key -keyform -keyout -md5 -sha1 -md2 -mdc2 \
  3640.                         -config -x509 -days -asn1-kludge -newhdr \
  3641.                         -extensions -reqexts section' -- $cur ) )
  3642.                 fi
  3643.                 ;;
  3644.             rsa)
  3645.                 case $prev in
  3646.                     -@(in|out)form)
  3647.                         COMPREPLY=( $( compgen -W 'DER NET PEM' -- $cur ) )
  3648.                         return 0
  3649.                         ;;
  3650.                     -@(in|out))
  3651.                         _filedir
  3652.                         return 0
  3653.                         ;;
  3654.                 esac
  3655.  
  3656.                 if [[ "$cur" == -* ]]; then
  3657.                     COMPREPLY=( $( compgen -W '-inform -outform -in -passin -out -passout \
  3658.                         -sgckey -des -des3 -idea -text -noout -modulus -check -pubin \
  3659.                         -pubout -engine' -- $cur ) )
  3660.                 fi
  3661.                 ;;
  3662.             rsautl)
  3663.                 case $prev in
  3664.                     -@(in|out|inkey))
  3665.                         _filedir
  3666.                         return 0
  3667.                         ;;
  3668.                 esac
  3669.  
  3670.                 if [[ "$cur" == -* ]]; then
  3671.                     COMPREPLY=( $( compgen -W '-in -out -inkey -pubin -certin -sign -verify \
  3672.                         -encrypt -decrypt -pkcs -ssl -raw -hexdump -asn1parse' -- $cur ) )
  3673.                 fi
  3674.                 ;;
  3675.             s_client)
  3676.                 case $prev in
  3677.                     -connect)
  3678.                         _known_hosts
  3679.                         return 0
  3680.                         ;;
  3681.                     -@(cert|key|CAfile|rand))
  3682.                         _filedir
  3683.                         return 0
  3684.                         ;;
  3685.                     -CApath)
  3686.                         _filedir -d
  3687.                         return 0
  3688.                         ;;
  3689.                 esac
  3690.  
  3691.                 if [[ "$cur" == -* ]]; then
  3692.                     COMPREPLY=( $( compgen -W '-connect -verify -cert -key -CApath -CAfile \
  3693.                         -reconnect -pause -showcerts -debug -msg -nbio_test -state -nbio \
  3694.                         -crlf -ign_eof -quiet -ssl2 -ssl3 -tls1 -no_ssl2 -no_ssl3 -no_tls1 \
  3695.                         -bugs -cipher -starttls -engine -rand' -- $cur ) )
  3696.                 fi
  3697.                 ;;
  3698.             s_server)
  3699.                 case $prev in
  3700.                     -@(cert|key|dcert|dkey|dhparam|CAfile|rand))
  3701.                         _filedir
  3702.                         return 0
  3703.                         ;;
  3704.                     -CApath)
  3705.                         _filedir -d
  3706.                         return 0
  3707.                         ;;
  3708.                 esac
  3709.  
  3710.                 if [[ "$cur" == -* ]]; then
  3711.                     COMPREPLY=( $( compgen -W '-accept -context -verify -Verify -cert -key \
  3712.                          -dcert -dkey -dhparam -nbio -nbio_test -crlf -debug -msg -state -CApath \
  3713.                          -CAfile -nocert -cipher -quiet -no_tmp_rsa -ssl2 -ssl3 -tls1 -no_ssl2 \
  3714.                          -no_ssl3 -no_tls1 -no_dhe -bugs -hack -www -WWW -HTTP -engine -id_prefix \
  3715.                          -rand' -- $cur ) )
  3716.                  fi
  3717.                  ;;
  3718.             s_time)
  3719.                 case $prev in
  3720.                     -connect)
  3721.                         _known_hosts
  3722.                         return 0
  3723.                         ;;
  3724.                     -@(cert|key|CAfile))
  3725.                         _filedir
  3726.                         return 0
  3727.                         ;;
  3728.                     -CApath)
  3729.                         _filedir -d
  3730.                         return 0
  3731.                         ;;
  3732.                 esac
  3733.  
  3734.                 if [[ "$cur" == -* ]]; then
  3735.                     COMPREPLY=( $( compgen -W '-connect -www -cert -key -CApath -CAfile -reuse \
  3736.                         -new -verify -nbio -time -ssl2 -ssl3 -bugs -cipher' -- $cur ) )
  3737.                 fi
  3738.                 ;;
  3739.  
  3740.             sess_id) 
  3741.                 case $prev in
  3742.                     -@(in|out)form)
  3743.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3744.                         return 0
  3745.                         ;;
  3746.                     -@(in|out))
  3747.                         _filedir
  3748.                         return 0
  3749.                         ;;
  3750.                 esac
  3751.  
  3752.  
  3753.                 if [[ "$cur" == -* ]]; then
  3754.                     COMPREPLY=( $( compgen -W '-inform -outform -in -out -text -noout \
  3755.                         -context ID' -- $cur ) )
  3756.                 fi
  3757.                 ;;
  3758.             smime)
  3759.                 case $prev in
  3760.                     -@(in|out)form)
  3761.                         COMPREPLY=( $( compgen -W 'SMIME DER PEM' -- $cur ) )
  3762.                         return 0
  3763.                         ;;
  3764.                     -@(in|out|certfile|signer|recip|inkey|content|rand))
  3765.                         _filedir
  3766.                         return 0
  3767.                         ;;
  3768.                 esac
  3769.  
  3770.                 if [[ "$cur" == -* ]]; then
  3771.                     COMPREPLY=( $( compgen -W '-encrypt -decrypt -sign -verify -pk7out -des -des3 \
  3772.                         -rc2-40 -rc2-64 -rc2-128 -aes128 -aes192 -aes256 -in -certfile -signer \
  3773.                         -recip -inform -passin -inkey -out -outform -content -to -from -subject \
  3774.                         -text -rand' -- $cur ) )
  3775.                 else
  3776.                         _filedir
  3777.                 fi
  3778.                 ;;
  3779.             speed)
  3780.                 if [[ "$cur" == -* ]]; then
  3781.                     COMPREPLY=( $( compgen -W '-engine' -- $cur ) )
  3782.                 else
  3783.                     COMPREPLY=( $( compgen -W 'md2 mdc2 md5 hmac sha1 rmd160 idea-cbc \
  3784.                         rc2-cbc rc5-cbc bf-cbc des-cbc des-ede3 rc4 rsa512 rsa1024 rsa2048 \
  3785.                         rsa4096 dsa512 dsa1024 dsa2048 idea rc2 des rsa blowfish' -- $cur ) )
  3786.                 fi
  3787.                 ;;
  3788.             verify)
  3789.                 case $prev in
  3790.                     -@(CAfile|untrusted))
  3791.                         _filedir
  3792.                         return 0
  3793.                         ;;
  3794.                     -CApath)
  3795.                         _filedir -d
  3796.                         return 0
  3797.                         ;;
  3798.                 esac
  3799.  
  3800.                 if [[ "$cur" == -* ]]; then
  3801.                     COMPREPLY=( $( compgen -W '-CApath -CAfile -purpose -untrusted -help -issuer_checks \
  3802.                         -verbose -certificates' -- $cur ) )
  3803.                 else
  3804.                         _filedir
  3805.                 fi
  3806.                 ;;
  3807.             x509)
  3808.                 case "$prev" in
  3809.                     -@(in|out|CA|CAkey|CAserial|extfile))
  3810.                         _filedir
  3811.                         return 0
  3812.                         ;;
  3813.                     -@(in|out)form)
  3814.                         COMPREPLY=( $( compgen -W 'DER PEM NET' -- $cur ) )
  3815.                         return 0
  3816.                         ;;
  3817.                     -@(key|CA|CAkey)form)
  3818.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3819.                         return 0
  3820.                         ;;
  3821.                     -extensions)
  3822.                         _openssl_sections
  3823.                         return 0
  3824.                         ;;
  3825.                 esac
  3826.  
  3827.                 if [[ "$cur" == -* ]]; then
  3828.                     COMPREPLY=( $( compgen -W '-inform -outform \
  3829.                         -keyform -CAform -CAkeyform -in -out \
  3830.                         -serial -hash -subject -issuer -nameopt \
  3831.                         -email -startdate -enddate -purpose \
  3832.                         -dates -modulus -fingerprint -alias \
  3833.                         -noout -trustout -clrtrust -clrreject \
  3834.                         -addtrust -addreject -setalias -days \
  3835.                         -set_serial -signkey -x509toreq -req \
  3836.                         -CA -CAkey -CAcreateserial -CAserial \
  3837.                         -text -C -md2 -md5 -sha1 -mdc2 -clrext \
  3838.                         -extfile -extensions -engine' -- $cur ) )
  3839.                 fi
  3840.                 ;;
  3841.             @(md5|md4|md2|sha1|sha|mdc2|ripemd160))
  3842.                 if [[ "$cur" == -* ]]; then
  3843.                     COMPREPLY=( $( compgen -W '-c -d' -- $cur ) )
  3844.                 else
  3845.                         _filedir
  3846.                 fi
  3847.                 ;;
  3848.         esac
  3849.     fi
  3850.  
  3851.     return 0
  3852. }
  3853. complete -F _openssl $default openssl
  3854. }
  3855.  
  3856. # screen(1) completion
  3857. #
  3858. have screen &&
  3859. _screen()
  3860. {
  3861.     local cur prev preprev
  3862.  
  3863.     COMPREPLY=()
  3864.     cur=${COMP_WORDS[COMP_CWORD]}
  3865.     prev=${COMP_WORDS[COMP_CWORD-1]}
  3866.  
  3867.     [ "$COMP_CWORD" -ge 2 ] && preprev=${COMP_WORDS[COMP_CWORD-2]}
  3868.  
  3869.     if [ "$preprev" = "-d" -o "$preprev" = "-D" -a "$prev" = "-r" -o \
  3870.          "$prev" = "-R" ]; then
  3871.         # list all
  3872.         COMPREPLY=( $( command screen -ls | \
  3873.                 sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*$|\1|p' ) )
  3874.     else
  3875.         case "$prev" in
  3876.         -[rR])
  3877.             # list detached
  3878.             COMPREPLY=( $( command screen -ls | \
  3879.                     sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*Detached.*$|\1|p' ) )
  3880.             ;;
  3881.         -[dDx])
  3882.             # list attached
  3883.             COMPREPLY=( $( command screen -ls | \
  3884.                     sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*Attached.*$|\1|p' ) )
  3885.             ;;
  3886.         -s)
  3887.             # shells
  3888.             COMPREPLY=( $( grep ^${cur:-[^#]} /etc/shells ) )
  3889.             ;;
  3890.         *)
  3891.             ;;
  3892.         esac
  3893.     fi
  3894.  
  3895.     return 0
  3896. } &&
  3897. complete -F _screen $default screen
  3898.  
  3899. # lftp(1) bookmark completion
  3900. #
  3901. have lftp &&
  3902. _lftp()
  3903. {
  3904.     local cur
  3905.  
  3906.     COMPREPLY=()
  3907.     cur=${COMP_WORDS[COMP_CWORD]}
  3908.  
  3909.     if [ $COMP_CWORD -eq 1 ] && [ -f ~/.lftp/bookmarks ]; then
  3910.         COMPREPLY=( $( compgen -W '$( sed -ne "s/^\(.*\)'$'\t''.*$/\1/p" \
  3911.                ~/.lftp/bookmarks )' -- $cur ) )
  3912.     fi
  3913.  
  3914.     return 0
  3915. } &&
  3916. complete -F _lftp $default lftp
  3917.  
  3918. # ncftp(1) bookmark completion
  3919. #
  3920. have ncftp &&
  3921. _ncftp()
  3922. {
  3923.     local cur
  3924.  
  3925.     COMPREPLY=()
  3926.     cur=${COMP_WORDS[COMP_CWORD]}
  3927.  
  3928.     if [ $COMP_CWORD -eq 1 ] && [ -f ~/.ncftp/bookmarks ]; then
  3929.         COMPREPLY=( $( compgen -W '$( sed -ne "s/^\([^,]\{1,\}\),.*$/\1/p" \
  3930.                ~/.ncftp/bookmarks )' -- $cur ) )
  3931.     fi
  3932.  
  3933.     return 0
  3934. } &&
  3935. complete -F _ncftp $default ncftp
  3936.  
  3937. # gdb(1) completion
  3938. #
  3939. have gdb &&
  3940. _gdb()
  3941. {
  3942.     local cur prev
  3943.  
  3944.     COMPREPLY=()
  3945.     cur=${COMP_WORDS[COMP_CWORD]}
  3946.     prev=${COMP_WORDS[COMP_CWORD-1]}
  3947.  
  3948.     if [ $COMP_CWORD -eq 1 ]; then
  3949.         COMPREPLY=( $( compgen -c -- $cur ) )
  3950.     elif [ $COMP_CWORD -eq 2 ]; then
  3951.         prev=${prev##*/}
  3952.         COMPREPLY=( $( compgen -fW "$( command ps axo comm,pid | \
  3953.                 awk '{if ($1 ~ /^'"$prev"'/) print $2}' ) )" \
  3954.                 -- "$cur" ) )
  3955.     fi
  3956. } &&
  3957. complete -F _gdb $filenames gdb
  3958.  
  3959. # Postgresql completion
  3960. #
  3961. have psql && {
  3962. _pg_databases() 
  3963. {
  3964.     COMPREPLY=( $( psql -l 2>/dev/null | \
  3965.             sed -e '1,/^-/d' -e '/^(/,$d' | \
  3966.             awk '{print $1}' | grep "^$cur" ) )
  3967. }
  3968.  
  3969. _pg_users()
  3970. {
  3971.     COMPREPLY=( $( psql -qtc 'select usename from pg_user' template1 2>/dev/null | \
  3972.             grep "^ $cur" ) )
  3973.     [ ${#COMPREPLY[@]} -eq 0 ] && COMPREPLY=( $( compgen -u -- $cur ) )
  3974. }
  3975.  
  3976. # createdb(1) completion
  3977. #
  3978. _createdb() 
  3979. {
  3980.     local cur prev
  3981.  
  3982.     COMPREPLY=()
  3983.     cur=${COMP_WORDS[COMP_CWORD]}
  3984.     prev=${COMP_WORDS[COMP_CWORD-1]}
  3985.  
  3986.     case "$prev" in
  3987.     -@(h|-host=)) 
  3988.         _known_hosts
  3989.         return 0
  3990.         ;;
  3991.     -@(U|-username=))
  3992.         _pg_users
  3993.         return 0
  3994.         ;;
  3995.     esac
  3996.  
  3997.     if [[ "$cur" == -* ]]; then
  3998.         COMPREPLY=( $( compgen -W '-D -T -E -h -p -U -W -e -q \
  3999.             --location= --template= --encoding= --host= --port= \
  4000.             --username= --password --echo --quiet --help' -- $cur ))
  4001.     else
  4002.         _pg_databases
  4003.     fi
  4004. }
  4005. complete -F _createdb $default createdb
  4006.  
  4007. # dropdb(1) completion
  4008. #
  4009. _dropdb() 
  4010. {
  4011.     local cur prev
  4012.  
  4013.     COMPREPLY=()
  4014.     cur=${COMP_WORDS[COMP_CWORD]}
  4015.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4016.  
  4017.     case "$prev" in
  4018.     -@(h|-host=)) 
  4019.         _known_hosts
  4020.         return 0
  4021.         ;;
  4022.     -@(U|-username=))
  4023.         _pg_users
  4024.         return 0
  4025.         ;;
  4026.     esac
  4027.  
  4028.     if [[ "$cur" == -* ]]; then
  4029.         COMPREPLY=( $( compgen -W '-h -p -U -W -e -q \
  4030.                 --host= --port= --username= --password \
  4031.                 --interactive --echo --quiet --help' -- $cur ) )
  4032.     else
  4033.         _pg_databases
  4034.     fi
  4035. }
  4036. complete -F _dropdb $default dropdb
  4037.  
  4038. # psql(1) completion
  4039. #
  4040. _psql() 
  4041. {
  4042.     local cur prev
  4043.  
  4044.     COMPREPLY=()
  4045.     cur=${COMP_WORDS[COMP_CWORD]}
  4046.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4047.  
  4048.     case "$prev" in
  4049.     -h|--host) 
  4050.         _known_hosts
  4051.         return 0
  4052.         ;;
  4053.     -U|--username)
  4054.         _pg_users
  4055.         return 0
  4056.         ;;
  4057.     -d|--dbname)
  4058.         _pg_databases
  4059.         return 0
  4060.         ;;
  4061.     -@(o|f)|--output|--file)
  4062.         _filedir
  4063.         return 0
  4064.         ;;
  4065.     esac
  4066.  
  4067.     if [[ "$cur" == -* ]]; then
  4068.         # return list of available options
  4069.         COMPREPLY=( $( compgen -W '-a --echo-all -A --no-align \
  4070.             -c --command -d --dbname -e --echo-queries \
  4071.             -E --echo-hidden -f --file -F --filed-separator \
  4072.             -h --host -H --html -l --list -n -o --output \
  4073.             -p --port -P --pset -q -R --record-separator \
  4074.             -s --single-step -S --single-line -t --tuples-only \
  4075.             -T --table-attr -U --username -v --variable \
  4076.             -V --version -W --password -x --expanded -X --nopsqlrc \
  4077.             -? --help ' -- $cur ) )
  4078.     else
  4079.         # return list of available databases
  4080.         _pg_databases
  4081.     fi
  4082. }
  4083. complete -F _psql $default psql
  4084. }
  4085.  
  4086. _longopt()
  4087. {
  4088.     local cur opt
  4089.  
  4090.     cur=${COMP_WORDS[COMP_CWORD]}
  4091.  
  4092.     if [[ "$cur" == --*=* ]]; then
  4093.         opt=${cur%%=*}
  4094.         # cut backslash that gets inserted before '=' sign
  4095.         opt=${opt%\\*}
  4096.         cur=${cur#*=}
  4097.         _filedir
  4098.         COMPREPLY=( $( compgen -P "$opt=" -W '${COMPREPLY[@]}' -- $cur))
  4099.         return 0
  4100.     fi
  4101.  
  4102.     if [[ "$cur" == -* ]]; then
  4103.         COMPREPLY=( $( $1 --help 2>&1 | sed -e '/--/!d' \
  4104.                 -e 's/.*\(--[-A-Za-z0-9]\+=\?\).*/\1/' | \
  4105.                    command grep "^$cur" | sort -u ) )
  4106.     elif [[ "$1" == @(mk|rm)dir ]]; then
  4107.         _filedir -d
  4108.     else
  4109.         _filedir
  4110.     fi
  4111. }
  4112. # makeinfo and texi2dvi are defined elsewhere.
  4113. for i in a2ps autoconf automake bc gprof ld nm objcopy objdump readelf strip \
  4114.      bison cpio diff patch enscript cp df dir du ln ls mkfifo mknod mv rm \
  4115.      touch vdir awk gperf grep grub indent less m4 sed shar date \
  4116.      tee who texindex cat csplit cut expand fmt fold head \
  4117.      md5sum nl od paste pr ptx sha1sum sort split tac tail tr unexpand \
  4118.      uniq wc ldd bash id irb mkdir rmdir; do
  4119.   have $i && complete -F _longopt $filenames $i
  4120. done
  4121.  
  4122. # These commands use filenames, so '-o filenames' is not needed.
  4123. for i in env netstat seq uname units wget; do
  4124.   have $i && complete -F _longopt $default $i
  4125. done
  4126. unset i
  4127.  
  4128. # gcc(1) completion
  4129. #
  4130. # The only unusual feature is that we don't parse "gcc --help -v" output
  4131. # directly, because that would include the options of all the other backend
  4132. # tools (linker, assembler, preprocessor, etc) without any indication that
  4133. # you cannot feed such options to the gcc driver directly.  (For example, the
  4134. # linker takes a -z option, but you must type -Wl,-z for gcc.)  Instead, we
  4135. # ask the driver ("g++") for the name of the compiler ("cc1"), and parse the
  4136. # --help output of the compiler.
  4137. #
  4138. have gcc &&
  4139. _gcc()
  4140. {
  4141.     local cur cc backend
  4142.  
  4143.     COMPREPLY=()
  4144.     cur=${COMP_WORDS[COMP_CWORD]}
  4145.  
  4146.     _expand || return 0
  4147.  
  4148.     case "$1" in
  4149.     gcj)
  4150.         backend=jc1
  4151.         ;;
  4152.     gpc)
  4153.         backend=gpc1
  4154.         ;;
  4155.     *77)
  4156.         backend=f771
  4157.         ;;
  4158.     *)
  4159.         backend=cc1    # (near-)universal backend
  4160.         ;;
  4161.     esac
  4162.  
  4163.     if [[ "$cur" == -* ]]; then
  4164.         cc=$( $1 -print-prog-name=$backend )
  4165.         # sink stderr:
  4166.         # for C/C++/ObjectiveC it's useless
  4167.         # for FORTRAN/Java it's an error
  4168.         COMPREPLY=( $( $cc --help 2>/dev/null | tr '\t' ' ' | \
  4169.                    sed -e '/^  *-/!d' -e 's/ *-\([^ ]*\).*/-\1/' | \
  4170.                    command grep "^$cur" | sort -u ) )
  4171.     else
  4172.         _filedir
  4173.     fi
  4174. } &&
  4175. complete $filenames -F _gcc gcc g++ c++ g77 gcj gpc
  4176. [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Cygwin ] && \
  4177. [ -n "${have:-}" ] && complete $filenames -F _gcc cc
  4178.  
  4179. # Linux cardctl(8) completion
  4180. #
  4181. have cardctl &&
  4182. _cardctl()
  4183. {
  4184.     local cur
  4185.  
  4186.     COMPREPLY=()
  4187.     cur=${COMP_WORDS[COMP_CWORD]}
  4188.  
  4189.     if [ $COMP_CWORD -eq 1 ]; then
  4190.         COMPREPLY=( $( compgen -W 'status config ident suspend \
  4191.                        resume reset eject insert scheme' \
  4192.                    -- $cur ) )
  4193.     fi
  4194. } &&
  4195. complete -F _cardctl cardctl
  4196.  
  4197. # This function is required by _dpkg() and _dpkg-reconfigure()
  4198. #
  4199. have dpkg && {
  4200. have grep-status && {
  4201. _comp_dpkg_installed_packages()
  4202. {
  4203.     grep-status -P -e "^$1" -a -FStatus 'install ok installed' -n -s Package
  4204. }
  4205. } || {
  4206. _comp_dpkg_installed_packages()
  4207. {
  4208.     grep -A 2 "Package: $1" /var/lib/dpkg/status | \
  4209.         grep -B 2 'ok installed' | grep "Package: $1" | cut -d\  -f2
  4210. }
  4211. }
  4212.  
  4213. # Debian dpkg(8) completion
  4214. #
  4215. _dpkg()
  4216. {
  4217.     local cur prev i
  4218.  
  4219.     COMPREPLY=()
  4220.     cur=${COMP_WORDS[COMP_CWORD]}
  4221.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4222.     i=$COMP_CWORD
  4223.  
  4224.     _expand || return 0
  4225.  
  4226.     # find the last option flag
  4227.     if [[ $cur != -* ]]; then
  4228.         while [[ $prev != -* && $i != 1 ]]; do
  4229.             i=$((i-1))
  4230.             prev=${COMP_WORDS[i-1]}
  4231.         done
  4232.     fi
  4233.  
  4234.     case "$prev" in 
  4235.     -@(c|i|A|I|f|e|x|X|-@(install|unpack|record-avail|contents|info| \
  4236.               fsys-tarfile|field|control|extract)))
  4237.         _filedir '?(u)deb'
  4238.         return 0
  4239.         ;;
  4240.     -@(b|-build))
  4241.         _filedir -d
  4242.         return 0
  4243.         ;;
  4244.        -@(s|p|l|-@(status|print-avail|list)))
  4245.         COMPREPLY=( $( apt-cache pkgnames $cur 2>/dev/null ) )
  4246.         return 0
  4247.         ;;
  4248.     -@(S|-search))
  4249.         _filedir
  4250.         return 0
  4251.         ;;
  4252.     -@(r|L|P|-@(remove|purge|listfiles)))
  4253.         COMPREPLY=( $( _comp_dpkg_installed_packages $cur ) )
  4254.         return 0
  4255.         ;;
  4256.     *)
  4257.  
  4258.     COMPREPLY=( $( compgen -W '-i --install --unpack -A --record-avail \
  4259.             --configure -r --remove -P --purge --get-selections \
  4260.             --set-selections --update-avail --merge-avail \
  4261.             --clear-avail  --command-fd --forget-old-unavail -s \
  4262.             --status -p --print-avail -L --listfiles -l --list \
  4263.             -S --search -C --audit --print-architecture \
  4264.             --print-gnu-build-architecture \
  4265.             --print-installation-architecture \
  4266.             --compare-versions --help --version --force-help \
  4267.             --force-all --force-auto-select --force-downgrade \
  4268.             --force-configure-any --force-hold --force-bad-path \
  4269.             --force-not-root --force-overwrite \
  4270.             --force-overwrite-diverted --force-bad-verify \
  4271.             --force-depends-version --force-depends \
  4272.             --force-confnew --force-confold --force-confdef \
  4273.             --force-confmiss --force-conflicts --force-architecture\
  4274.             --force-overwrite-dir --force-remove-reinstreq \
  4275.             --force-remove-essential -Dh \
  4276.             --debug=help --licence --admindir= --root= --instdir= \
  4277.             -O --selected-only -E --skip-same-version \
  4278.             -G --refuse-downgrade -B --auto-deconfigure \
  4279.             --no-debsig --no-act -D --debug= --status-fd \
  4280.             -b --build -I --info -f --field -c --contents \
  4281.             -x --extract -X --vextract --fsys-tarfile -e --control \
  4282.             --ignore-depends= --abort-after' -- $cur ) )
  4283.         ;;
  4284.     esac
  4285.  
  4286.  
  4287. }
  4288. complete -F _dpkg $filenames dpkg dpkg-deb
  4289. }
  4290.  
  4291. # Debian GNU dpkg-reconfigure(8) completion
  4292. #
  4293. have dpkg-reconfigure &&
  4294. _dpkg_reconfigure()
  4295. {
  4296.     local cur prev opt
  4297.  
  4298.     COMPREPLY=()
  4299.     cur=${COMP_WORDS[COMP_CWORD]}
  4300.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4301.  
  4302.  
  4303.     case "$prev" in
  4304.         -@(f|-frontend))
  4305.         opt=( $( echo /usr/share/perl5/Debconf/FrontEnd/* ) )
  4306.         opt=( ${opt[@]##*/} )
  4307.         opt=( ${opt[@]%.pm} )
  4308.         COMPREPLY=( $( compgen -W '${opt[@]}' -- $cur ) )
  4309.         return 0
  4310.         ;;
  4311.         -@(p|-priority))
  4312.           COMPREPLY=( $( compgen -W 'low medium high critical' -- $cur ) )
  4313.         return 0
  4314.         ;;
  4315.     esac
  4316.  
  4317.     if [[ "$cur" == -* ]]; then
  4318.         COMPREPLY=( $( compgen -W '-f --frontend -p --priority -a --all \
  4319.                        -u --unseen-only -h --help -s --showold \
  4320.                        --force --terse' -- $cur ) )
  4321.     else
  4322.         COMPREPLY=( $( _comp_dpkg_installed_packages $cur ) )
  4323.     fi
  4324. } &&
  4325. complete -F _dpkg_reconfigure $default dpkg-reconfigure
  4326.  
  4327. # Debian dpkg-source completion
  4328. #
  4329. have dpkg-source &&
  4330. _dpkg_source()
  4331. {
  4332.     local cur prev options work i action packopts unpackopts
  4333.  
  4334.     packopts="-c -l -F -V -T -D -U -W -E -sa -i -I -sk -sp -su -sr -ss -sn -sA -sK -sP -sU -sR"
  4335.     unpackopts="-sp -sn -su"
  4336.     options=`echo "-x -b $packopts $unpackopts" | xargs echo | sort -u | xargs echo`
  4337.  
  4338.     COMPREPLY=()
  4339.     if [ "$1" != "dpkg-source" ]; then
  4340.         exit 1
  4341.     fi
  4342.     cur=${COMP_WORDS[COMP_CWORD]}
  4343.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4344.     action="options"
  4345.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  4346.         if [[ ${COMP_WORDS[$i]} == "-x" ]]; then
  4347.             action=unpack
  4348.         elif [[ ${COMP_WORDS[$i]} == "-b" ]]; then
  4349.             action=pack
  4350.         elif [[ ${COMP_WORDS[$i]} == "-h" ]]; then
  4351.             action=help
  4352.         fi
  4353.     done
  4354.     # if currently seeing a complete option, return just itself.
  4355.     for i in $options; do
  4356.         if [ "$cur" = "$i" ]; then
  4357.             COMPREPLY=( "$cur" )
  4358.             return 0
  4359.         fi
  4360.     done
  4361.     case "$action" in
  4362.         "unpack")
  4363.             if [ "$cur" = "-" -o "$cur" = "-s" ]; then
  4364.                 COMPREPLY=( $unpackots )
  4365.                 return 0
  4366.             fi
  4367.             case "$prev" in
  4368.                 "-x")
  4369.                     COMPREPLY=( $( compgen -d -- "$cur" ) \
  4370.                             $( compgen -f -X '!*.dsc' -- "$cur" ) )
  4371.                     return 0
  4372.                     ;;
  4373.                 *)
  4374.                     COMPREPLY=( $unpackopts $(compgen -d -f -- "$cur" ) )
  4375.                     return 0
  4376.                     ;;
  4377.             esac
  4378.             return 0
  4379.             ;;
  4380.         "pack")
  4381.             if [ "$cur" = "-" ]; then
  4382.                 COMPREPLY=( $packopts )
  4383.                 return 0
  4384.             fi
  4385.             if [ "$cur" = "-s" ]; then
  4386.                 COMPREPLY=( "-sa" "-sk" "-sp" "-su" "-sr" "-ss" "-sn" \
  4387.                         "-sA" "-sK" "-sP" "-sU" "-sR" )
  4388.                 return 0
  4389.             fi
  4390.             case "$prev" in
  4391.                 "-b")
  4392.                     COMPREPLY=( $( compgen -d -- "$cur" ) )
  4393.                     return 0
  4394.                     ;;
  4395.                 "-c"|"-l"|"-T"|"-i"|"-I")
  4396.                     # -c: get controlfile
  4397.                     # -l: get per-version info from this file
  4398.                     # -T: read variables here, not debian/substvars
  4399.                     # -i: <regexp> filter out files to ignore diffs of.
  4400.                     # -I: filter out files when building tarballs.
  4401.                     # return directory names and file names
  4402.                     COMPREPLY=( $( compgen -d -f ) )
  4403.                     return 0
  4404.                     ;;
  4405.                 "-F")
  4406.                     # -F: force change log format
  4407.                     COMPREPLY=( $( ( cd /usr/lib/dpkg/parsechangelog; compgen -f "$cur" ) ) )
  4408.                     return 0
  4409.                     ;;
  4410.                 "-V"|"-D")
  4411.                     # -V: set a substitution variable
  4412.                     # we don't know anything about possible variables or values
  4413.                     # so we don't try to suggest any completion.
  4414.                     COMPREPLY=()
  4415.                     return 0
  4416.                     ;;
  4417.                 "-D")
  4418.                     # -D: override or add a .dsc field and value
  4419.                     # if $cur doesn't contain a = yet, suggest variable names
  4420.                     if echo -- "$cur" | grep -q "="; then
  4421.                         # $cur contains a "="
  4422.                         COMPREPLY=()
  4423.                         return 0
  4424.                     else
  4425.                         COMPREPLY=( Format Source Version Binary Maintainer Uploader Architecture Standards-Version Build-Depends Files )
  4426.                         return 0
  4427.                     fi
  4428.                     ;;
  4429.                 "-U")
  4430.                     # -U: remove a field
  4431.                     # Suggest possible fieldnames
  4432.                     COMPREPLY=( Format Source Version Binary Maintainer Uploader Architecture Standards-Version Build-Depends Files )
  4433.                     return 0
  4434.                     ;;
  4435.                 *)
  4436.                     COMPREPLY=( $packopts )
  4437.                     return 0
  4438.                     ;;
  4439.             esac
  4440.             return 0
  4441.             ;;
  4442.         *)
  4443.             # if seeing a partial option, return possible completions.
  4444.             if [ "$cur" = "-s" ]; then
  4445.                 COMPREPLY=( "-sa" "-sk" "-sp" "-su" "-sr" "-ss" "-sn" \
  4446.                         "-sA" "-sK" "-sP" "-sU" "-sR" )
  4447.                 return 0
  4448.             fi
  4449.             # else return all possible options.
  4450.             COMPREPLY=( $options )
  4451.             return 0
  4452.             ;;
  4453.     esac
  4454. } &&
  4455. complete -F _dpkg_source dpkg-source
  4456.  
  4457. # Debian Linux dselect(8) completion.
  4458. #
  4459. have dselect &&
  4460. _dselect()
  4461. {
  4462.     local cur prev
  4463.  
  4464.     COMPREPLY=()
  4465.     cur=${COMP_WORDS[COMP_CWORD]}
  4466.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4467.  
  4468.     case "$prev" in
  4469.          --admindir)
  4470.           _filedir -d
  4471.           return 0
  4472.           ;;
  4473.  
  4474.          -@(D|debug))
  4475.           _filedir
  4476.           return 0
  4477.           ;;
  4478.     esac
  4479.  
  4480.     if [[ "$cur" == -* ]]; then
  4481.         COMPREPLY=( $( compgen -W '--admindir --help --version --licence \
  4482.                   --license --expert --debug' -- $cur ) )
  4483.     else
  4484.         COMPREPLY=( $( compgen -W 'access update select install config \
  4485.                   remove quit' -- $cur ) )
  4486.     fi
  4487.  
  4488.  
  4489.     return 0
  4490. } &&
  4491. complete -F _dselect $filenames dselect
  4492.  
  4493. # Java completion
  4494. #
  4495.  
  4496. # available path elements completion
  4497. have java && {
  4498. _java_path()
  4499. {
  4500.     cur=${cur##*:}
  4501.     _filedir '@(jar|zip)'
  4502. }
  4503.  
  4504. # exact classpath determination
  4505. _java_find_classpath()
  4506. {
  4507.     local i
  4508.  
  4509.     # search first in current options
  4510.     for (( i=1; i < COMP_CWORD; i++ )); do
  4511.         if [[ "${COMP_WORDS[i]}" == -@(cp|classpath) ]]; then
  4512.             classpath=${COMP_WORDS[i+1]}
  4513.             break
  4514.         fi
  4515.     done
  4516.  
  4517.     # default to environment
  4518.     [ -z "$classpath" ] && classpath=$CLASSPATH
  4519.  
  4520.     # default to current directory
  4521.     [ -z "$classpath" ] && classpath=.
  4522. }
  4523.  
  4524. # exact sourcepath determination
  4525. _java_find_sourcepath()
  4526. {
  4527.     local i
  4528.  
  4529.     # search first in current options
  4530.     for (( i=1; i < COMP_CWORD; i++ )); do
  4531.         if [[ "${COMP_WORDS[i]}" == -sourcepath ]]; then
  4532.             sourcepath=${COMP_WORDS[i+1]}
  4533.             break
  4534.         fi
  4535.     done
  4536.  
  4537.     # default to classpath
  4538.     [ -z "$sourcepath" ] && _java_find_classpath
  4539.     sourcepath=$classpath
  4540. }
  4541.  
  4542. # available classes completion
  4543. _java_classes()
  4544. {
  4545.     local classpath i
  4546.  
  4547.     # find which classpath to use
  4548.     _java_find_classpath
  4549.  
  4550.     # convert package syntax to path syntax
  4551.     cur=${cur//.//}
  4552.     # parse each classpath element for classes
  4553.     for i in ${classpath//:/ }; do
  4554.         if [ -r $i ] && [[ "$i" == *.@(jar|zip) ]]; then
  4555.             if type zipinfo &> /dev/null; then
  4556.                 COMPREPLY=( ${COMPREPLY[@]} $( zipinfo -1 \
  4557.                 "$i" | grep "^$cur" | grep '\.class$' | \
  4558.                 grep -v "\\$" ) )
  4559.             else
  4560.                 COMPREPLY=( ${COMPREPLY[@]} $( jar tf "$i" \
  4561.                 "$cur" | grep "\.class$" | grep -v "\\$" ) )
  4562.             fi
  4563.  
  4564.         elif [ -d $i ]; then
  4565.             i=${i%/}
  4566.             COMPREPLY=( ${COMPREPLY[@]} $( find "$i" -type f \
  4567.             -path "$i/$cur*.class" 2>/dev/null | \
  4568.             grep -v "\\$" | sed -e "s|^$i/||" ) )
  4569.         fi
  4570.     done
  4571.  
  4572.     # remove class extension
  4573.     COMPREPLY=( ${COMPREPLY[@]%.class} )
  4574.     # convert path syntax to package syntax
  4575.     COMPREPLY=( ${COMPREPLY[@]//\//.} )
  4576. }
  4577.  
  4578. # available packages completion
  4579. _java_packages()
  4580. {
  4581.     local sourcepath i
  4582.  
  4583.     # find wich sourcepath to use
  4584.     _java_find_sourcepath
  4585.  
  4586.     # convert package syntax to path syntax
  4587.     cur=${cur//.//}
  4588.     # parse each sourcepath element for packages
  4589.     for i in ${sourcepath//:/ }; do
  4590.         if [ -d $i ]; then
  4591.             COMPREPLY=( ${COMPREPLY[@]} $( command ls -F -d \
  4592.                 $i/$cur* 2>/dev/null | sed -e 's|^'$i'/||' ) )
  4593.         fi
  4594.     done
  4595.     # keep only packages
  4596.     COMPREPLY=( $( echo ${COMPREPLY[@]} | tr " " "\n" | grep "/$" ) )
  4597.     # remove packages extension
  4598.     COMPREPLY=( ${COMPREPLY[@]%/} )
  4599.     # convert path syntax to package syntax
  4600.     cur=${COMPREPLY[@]//\//.}
  4601. }
  4602.  
  4603. # java completion
  4604. #
  4605. _java()
  4606. {
  4607.     local cur prev i
  4608.  
  4609.     COMPREPLY=()
  4610.     cur=${COMP_WORDS[COMP_CWORD]}
  4611.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4612.  
  4613.     for ((i=1; i < $COMP_CWORD; i++)); do
  4614.         case ${COMP_WORDS[$i]} in
  4615.             -cp|-classpath)
  4616.             ((i++))    # skip the classpath string.
  4617.             ;;
  4618.             -*)
  4619.             # this is an option, not a class/jarfile name.
  4620.             ;;
  4621.             *)
  4622.             # once we've seen a class, just do filename completion
  4623.             _filedir
  4624.             return 0
  4625.             ;;
  4626.         esac
  4627.     done
  4628.  
  4629.     case $prev in
  4630.         -@(cp|classpath))
  4631.             _java_path
  4632.             return 0
  4633.             ;;
  4634.     esac
  4635.  
  4636.     if [[ "$cur" == -* ]]; then
  4637.         # relevant options completion
  4638.         COMPREPLY=( $( compgen -W '-client -hotspot -server -classic \
  4639.                 -cp -classpath -D -verbose -verbose:class \
  4640.                 -verbose:gc -version:jni -version \
  4641.                 -showversion -? -help -X -jar \
  4642.                 -ea -enableassertions -da -disableassertions \
  4643.                 -esa -enablesystemassertions \
  4644.                 -dsa -disablesystemassertions ' -- $cur ) )
  4645.     else
  4646.         if [[ "$prev" == -jar ]]; then
  4647.             # jar file completion
  4648.             _filedir jar
  4649.         else
  4650.             # classes completion
  4651.             _java_classes
  4652.         fi
  4653.     fi
  4654. }
  4655. complete -F _java $filenames java
  4656. }
  4657.  
  4658. # javadoc completion
  4659. #
  4660. have javadoc &&
  4661. _javadoc()
  4662. {
  4663.     COMPREPLY=()
  4664.     local cur prev
  4665.  
  4666.     cur=${COMP_WORDS[COMP_CWORD]}
  4667.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4668.  
  4669.     case $prev in
  4670.         -@(overview|helpfile|stylesheetfile))
  4671.             _filedir
  4672.             return 0
  4673.             ;;
  4674.         -d)
  4675.             _filedir -d
  4676.             return 0
  4677.             ;;
  4678.         -@(classpath|bootclasspath|docletpath|sourcepath|extdirs))
  4679.             _java_path
  4680.             return 0
  4681.             ;;
  4682.     esac
  4683.  
  4684.     if [[ "$cur" == -* ]]; then
  4685.         # relevant options completion
  4686.         COMPREPLY=( $( compgen -W '-overview -public -protected \
  4687.                 -package -private -help -doclet -docletpath \
  4688.                 -sourcepath -classpath -exclude -subpackages \
  4689.                 -breakiterator -bootclasspath -source -extdirs \
  4690.                 -verbose -locale -encoding -J -d -use -version \
  4691.                 -author -docfilessubdirs -splitindex \
  4692.                 -windowtitle -doctitle -header -footer -bottom \
  4693.                 -link -linkoffline -excludedocfilessubdir \
  4694.                 -group -nocomment -nodeprecated -noqualifier \
  4695.                 -nosince -nodeprecatedlist -notree -noindex \
  4696.                 -nohelp -nonavbar -quiet -serialwarn -tag \
  4697.                 -taglet -tagletpath -charset -helpfile \
  4698.                 -linksource -stylesheetfile -docencoding' -- \
  4699.                 $cur ) )
  4700.     else
  4701.         # source files completion
  4702.         _filedir java
  4703.         # packages completion
  4704.         _java_packages
  4705.     fi
  4706. } &&
  4707. complete -F _javadoc $filenames javadoc
  4708.  
  4709. # javac completion
  4710. #
  4711. have javac &&
  4712. _javac()
  4713. {
  4714.     COMPREPLY=()
  4715.     local cur prev
  4716.  
  4717.     cur=${COMP_WORDS[COMP_CWORD]}
  4718.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4719.  
  4720.     case $prev in
  4721.         -d)
  4722.             _filedir -d
  4723.             return 0
  4724.             ;;
  4725.         -@(classpath|bootclasspath|sourcepath|extdirs))
  4726.             _java_path
  4727.             return 0
  4728.             ;;
  4729.     esac
  4730.  
  4731.     if [[ "$cur" == -* ]]; then
  4732.         # relevant options completion
  4733.         COMPREPLY=( $( compgen -W '-g -g:none -g:lines -g:vars\
  4734.         -g:source -O -nowarn -verbose -deprecation -classpath\
  4735.         -sourcepath -bootclasspath -extdirs -d -encoding -source\
  4736.         -target -help' -- $cur ) )
  4737.     else
  4738.         # source files completion
  4739.         _filedir java
  4740.     fi
  4741. } &&
  4742. complete -F _javac $filenames javac
  4743.  
  4744. # PINE address-book completion
  4745. #
  4746. have pine &&
  4747. _pineaddr()
  4748. {
  4749.     local cur
  4750.  
  4751.     COMPREPLY=()
  4752.     cur=${COMP_WORDS[COMP_CWORD]}
  4753.  
  4754.     COMPREPLY=( $( compgen -W '$( awk "{print \$1}" ~/.addressbook 2>/dev/null)' \
  4755.             -- $cur ) )
  4756. } &&
  4757. complete -F _pineaddr $default pine
  4758.  
  4759. # mutt completion
  4760. #
  4761. # Mutt doesn't have an "addressbook" like Pine, but it has aliases and
  4762. # a "query" function to retrieve addresses, so that's what we use here.
  4763. have mutt || have muttng && {
  4764. _muttaddr()
  4765. {
  4766.     _muttaliases
  4767.     _muttquery
  4768.     return 0
  4769. }
  4770.  
  4771. _muttconffiles()
  4772. {
  4773.     local file sofar
  4774.     local -a newconffiles
  4775.  
  4776.     sofar=" $1 "
  4777.     shift
  4778.     while [[ "$1" ]]; do
  4779.         newconffiles=( $(sed -rn 's|^source[[:space:]]+([^[:space:]]+).*$|\1|p' $(eval echo $1) ) )
  4780.         for file in ${newconffiles[@]}; do
  4781.         [[ ! "$file" ]] || [[ "${sofar/ ${file} / }" != "$sofar" ]] &&
  4782.             continue
  4783.         sofar="$sofar $file"
  4784.         sofar=" $(eval _muttconffiles \"$sofar\" $file) "
  4785.         done
  4786.         shift
  4787.     done
  4788.     echo $sofar
  4789. }
  4790.  
  4791. _muttaliases()
  4792. {
  4793.     local cur muttrc
  4794.     local -a conffiles aliases
  4795.     cur=${COMP_WORDS[COMP_CWORD]}
  4796.  
  4797.     [ -f ~/.${muttcmd}/${muttcmd}rc ] && muttrc="~/.${muttcmd}/${muttcmd}rc"
  4798.     [ -f ~/.${muttcmd}rc ] && muttrc="~/.${muttcmd}rc"
  4799.     [ -z "$muttrc" ] && return 0
  4800.  
  4801.     conffiles=( $(eval _muttconffiles $muttrc $muttrc) )
  4802.     aliases=( $( sed -rn 's|^alias[[:space:]]+([^[:space:]]+).*$|\1|p' \
  4803.             $(eval echo ${conffiles[@]}) ) )
  4804.     COMPREPLY=( ${COMPREPLY[@]} $( compgen -W "${aliases[*]}" -- $cur ) )
  4805.  
  4806.     return 0
  4807. }
  4808.  
  4809. _muttquery()
  4810. {
  4811.     local cur querycmd
  4812.     local -a queryresults
  4813.     cur=${COMP_WORDS[COMP_CWORD]}
  4814.  
  4815.     querycmd="$( $muttcmd -Q query_command  | sed -r 's|^query_command=\"(.*)\"$|\1|; s|%s|'$cur'|' )"
  4816.     if [ -z "$cur" -o -z "$querycmd" ]; then
  4817.         queryresults=()
  4818.     else 
  4819.         queryresults=( $( $querycmd | \
  4820.           sed -nr '2,$s|^([^[:space:]]+).*|\1|p' ) )
  4821.     fi
  4822.  
  4823.     COMPREPLY=( ${COMPREPLY[@]} $( compgen -W "${queryresults[*]}" \
  4824.             -- $cur ) )
  4825.  
  4826.     return 0
  4827. }
  4828.  
  4829. _muttfiledir()
  4830. {
  4831.     local cur folder spoolfile
  4832.     cur=${COMP_WORDS[COMP_CWORD]}
  4833.  
  4834.     # This is currently not working so well. Perhaps this function should
  4835.     # just call _filedir() for the moment.
  4836.     if [[ $cur == [=+]* ]]; then
  4837.         folder="$( $muttcmd -Q folder | sed -r 's|^folder=\"(.*)\"$|\1|' )"
  4838.         : folder:=~/Mail
  4839.  
  4840.         # Match any file in $folder beginning with $cur
  4841.         # (minus the leading '=' sign).
  4842.         COMPREPLY=( $( compgen -f -- "$folder/${cur:1}" ) )
  4843.         COMPREPLY=( ${COMPREPLY[@]#$folder/} )
  4844.         return 0
  4845.     elif [ "$cur" == !* ]; then
  4846.         spoolfile="$( $muttcmd -Q spoolfile | sed -r 's|^spoolfile=\"(.*)\"$|\1|' )"
  4847.         [ ! -z "$spoolfile" ] && eval cur="${cur/^!/$spoolfile}";
  4848.     fi
  4849.     _filedir
  4850.  
  4851.     return 0
  4852. }
  4853.  
  4854. _mutt()
  4855. {
  4856.     local cur prev
  4857.     cur=${COMP_WORDS[COMP_CWORD]}
  4858.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4859.  
  4860.     COMPREPLY=()
  4861.     
  4862.     [ ${COMP_WORDS[0]} == muttng ] && muttcmd="muttng" || muttcmd="mutt"
  4863.  
  4864.     case "$cur" in
  4865.     -*)
  4866.         COMPREPLY=( $( compgen -W '-A -a -b -c -e -f -F -H -i -m -n \
  4867.                         -p -Q -R -s -v -x -y -z -Z -h' \
  4868.                         -- $cur ) )
  4869.         return 0
  4870.         ;;
  4871.     *)
  4872.         case "$prev" in
  4873.         -@(a|f|F|H|i))
  4874.             _muttfiledir
  4875.             return 0
  4876.             ;;
  4877.         -A)
  4878.             _muttaliases
  4879.             return 0
  4880.             ;;
  4881.         -@(e|m|Q|s|h|p|R|v|y|z|Z))
  4882.             return 0
  4883.             ;;
  4884.         *)
  4885.             _muttaddr
  4886.             return 0
  4887.             ;;
  4888.         esac
  4889.         ;;
  4890.     esac
  4891.     
  4892. }
  4893. complete -F _mutt $default $filenames mutt muttng
  4894. }
  4895.  
  4896. _configure_func()
  4897. {
  4898.     local cur
  4899.  
  4900.     COMPREPLY=()
  4901.     cur=${COMP_WORDS[COMP_CWORD]}
  4902.  
  4903.     # if $COMP_CONFIGURE_HINTS is not null, then completions of the form
  4904.     # --option=SETTING will include 'SETTING' as a contextual hint
  4905.     [[ "$cur" != -* ]] && return 0
  4906.  
  4907.     if [ -n "$COMP_CONFIGURE_HINTS" ]; then
  4908.         COMPREPLY=( $( $1 --help | awk '/^  --[A-Za-z]/ { print $1; if ($2 ~ /--[A-Za-z]/) print $2 }' | sed -e 's/[[,].*//g' | grep ^$cur ) )
  4909.  
  4910.     else
  4911.         COMPREPLY=( $( $1 --help | awk '/^  --[A-Za-z]/ { print $1; if ($2 ~ /--[A-Za-z]/) print $2 }' | sed -e 's/[[,=].*//g' | grep ^$cur ) )
  4912.     fi
  4913. }
  4914. complete -F _configure_func $default configure
  4915.  
  4916. # Debian reportbug(1) completion
  4917. #
  4918. have reportbug &&
  4919. _reportbug()
  4920. {
  4921.     local cur prev
  4922.  
  4923.     COMPREPLY=()
  4924.     cur=${COMP_WORDS[COMP_CWORD]}
  4925.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4926.  
  4927.     case "$prev" in
  4928.         -f|--filename|-i|--include|--mta|-o|--output)
  4929.         _filedir
  4930.         return 0
  4931.         ;;
  4932.         -B|--bts)
  4933.         COMPREPLY=( $( compgen -W "debian guug kde mandrake help" -- \
  4934.                    $cur ))
  4935.         return 0
  4936.         ;;
  4937.         -e|--editor|--mua)
  4938.         COMP_WORDS=(COMP_WORDS[0] $cur)
  4939.         COMP_CWORD=1
  4940.         _command
  4941.         return 0
  4942.         ;;
  4943.         --mode)
  4944.         COMPREPLY=( $( compgen -W "novice standard expert" -- $cur ) )
  4945.         return 0
  4946.         ;;
  4947.         -S|--severity)
  4948.         COMPREPLY=( $( compgen -W "grave serious important normal \
  4949.                        minor wishlist" -- $cur ) )
  4950.         return 0
  4951.         ;;
  4952.         -u|--ui|--interface)
  4953.         COMPREPLY=( $( compgen -W "newt text gnome" -- $cur ) )
  4954.         return 0
  4955.         ;;
  4956.         -t|--type)
  4957.         COMPREPLY=( $( compgen -W "gnats debbugs" -- $cur ) )
  4958.         return 0
  4959.         ;;
  4960.         -T|--tags)
  4961.         COMPREPLY=( $( compgen -W "none patch security upstream sid \
  4962.                        woody potato sarge fixed" -- $cur ))
  4963.         return 0
  4964.         ;;
  4965.         *)
  4966.         ;;
  4967.     esac
  4968.     
  4969.     COMPREPLY=($( compgen -W '-h --help -v --version -a --af -b \
  4970.             --no-query-bts --query-bts -B --bts -c --configure \
  4971.             --no-config-files --check-available -d --debug \
  4972.             --no-check-available -e --editor --email -f \
  4973.             --filename -g --gnupg -H --header -i --include -j \
  4974.             --justification -l --ldap --no-ldap -L --list-cc -m \
  4975.             --maintonly --mode --mua --mta --mutt -n --mh --nmh \
  4976.             -o --output -p --print -P --pgp --proxy --http_proxy\
  4977.             -q --quiet -Q --query-only --realname --report-quiet \
  4978.             --reply-to --replyto -s --subject -S --severity \
  4979.             --smtphost -t --type -T --tags --template -V -x \
  4980.             --no-cc --package-version -z --no-compress \
  4981.             --ui --interface -u \
  4982.             wnpp boot-floppies kernel-image' -- $cur ) \
  4983.                 $( apt-cache pkgnames -- $cur 2> /dev/null ) )
  4984.     _filedir
  4985.     return 0
  4986. } &&
  4987. complete -F _reportbug $filenames reportbug
  4988.  
  4989. # Debian querybts(1) completion
  4990. #
  4991. have querybts &&
  4992. _querybts()
  4993. {
  4994.     local cur prev
  4995.  
  4996.     COMPREPLY=()
  4997.     cur=${COMP_WORDS[COMP_CWORD]}
  4998.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4999.  
  5000.     case "$prev" in
  5001.         -B|--bts)
  5002.         COMPREPLY=( $( compgen -W "debian guug kde mandrake help" -- \
  5003.                    $cur ))
  5004.         return 0
  5005.         ;;
  5006.         -u|--ui|--interface)
  5007.         COMPREPLY=($( compgen -W "newt text gnome" -- $cur ))
  5008.         return 0
  5009.         ;;
  5010.         *)
  5011.         ;;
  5012.     esac
  5013.  
  5014.     COMPREPLY=($( compgen -W '-h --help -v --version -A --archive \
  5015.             -B --bts -l --ldap --no-ldap --proxy= --http_proxy= \
  5016.             -s --source -w --web -u --ui --interface \
  5017.             wnpp boot-floppies' -- $cur ) \
  5018.                 $( apt-cache pkgnames -- $cur 2> /dev/null ) )
  5019. } &&
  5020. complete -F _querybts $filenames querybts
  5021.  
  5022. # update-alternatives completion
  5023. #
  5024. have update-alternatives && {
  5025. installed_alternatives()
  5026. {
  5027.     local admindir
  5028.     # find the admin dir
  5029.     for i in alternatives dpkg/alternatives rpm/alternatives; do
  5030.         [ -d /var/lib/$i ] && admindir=/var/lib/$i && break
  5031.     done
  5032.     for (( i=1; i < COMP_CWORD; i++ )); do
  5033.         if [[ "${COMP_WORDS[i]}" == --admindir ]]; then
  5034.             admindir=${COMP_WORDS[i+1]}
  5035.             break
  5036.         fi
  5037.     done
  5038.     COMPREPLY=( $( command ls $admindir | grep "^$cur" ) )
  5039. }
  5040.  
  5041. _update_alternatives()
  5042. {
  5043.     local cur prev mode args i
  5044.  
  5045.     COMPREPLY=()
  5046.     cur=${COMP_WORDS[COMP_CWORD]}
  5047.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5048.  
  5049.     case "$prev" in
  5050.     --@(altdir|admindir))
  5051.         _filedir -d
  5052.         return 0
  5053.         ;;
  5054.     --@(help|version))
  5055.         return 0
  5056.         ;;
  5057.     esac
  5058.  
  5059.     # find wich mode to use and how many real args used so far
  5060.     for (( i=1; i < COMP_CWORD; i++ )); do
  5061.         if [[ "${COMP_WORDS[i]}" == --@(install|remove|auto|display|config) ]]; then
  5062.             mode=${COMP_WORDS[i]}
  5063.             args=$(($COMP_CWORD - i))
  5064.             break
  5065.         fi
  5066.     done
  5067.  
  5068.     case $mode in
  5069.     --install)
  5070.         case $args in
  5071.         1)
  5072.             _filedir
  5073.             ;;
  5074.         2)
  5075.             installed_alternatives
  5076.             ;;
  5077.         3)
  5078.             _filedir
  5079.             ;;
  5080.         esac
  5081.         ;;
  5082.     --remove)
  5083.         case $args in
  5084.         1)
  5085.             installed_alternatives
  5086.             ;;
  5087.         2)
  5088.             _filedir
  5089.             ;;
  5090.         esac
  5091.         ;;
  5092.     --auto)
  5093.         installed_alternatives
  5094.         ;;
  5095.     --display)
  5096.         installed_alternatives
  5097.         ;;
  5098.     --config)
  5099.         installed_alternatives
  5100.         ;;
  5101.     *)
  5102.         COMPREPLY=( $( compgen -W '--verbose --quiet --help --version \
  5103.                    --altdir --admindir' -- $cur ) \
  5104.                 $( compgen -W '--install --remove --auto --display \
  5105.                    --config' -- $cur ) )
  5106.     esac
  5107. }
  5108. complete -F _update_alternatives update-alternatives
  5109. }
  5110.  
  5111. # Python completion
  5112. #
  5113. have python &&
  5114. _python()
  5115. {
  5116.     local prev cur
  5117.  
  5118.     COMPREPLY=()
  5119.     cur=${COMP_WORDS[COMP_CWORD]}
  5120.     prev=${COMP_WORDS[COMP_CWORD-1]##*/}
  5121.  
  5122.     case "$prev" in
  5123.     -Q)
  5124.         COMPREPLY=( $( compgen -W "old new warn warnall" -- $cur ) )
  5125.         return 0
  5126.         ;;
  5127.     -W)
  5128.         COMPREPLY=( $( compgen -W "ignore default all module once error" -- $cur ) )
  5129.         return 0
  5130.         ;;
  5131.     -c)
  5132.         _filedir '@(py|pyc|pyo)'
  5133.         return 0
  5134.         ;;
  5135.     !(python|-?))
  5136.         [[ ${COMP_WORDS[COMP_CWORD-2]} != -@(Q|W) ]] && _filedir
  5137.         ;;
  5138.     esac
  5139.  
  5140.  
  5141.     # if '-c' is already given, complete all kind of files.
  5142.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  5143.         if [[ ${COMP_WORDS[i]} == -c ]]; then
  5144.             _filedir
  5145.         fi
  5146.     done
  5147.  
  5148.  
  5149.     if [[ "$cur" != -* ]]; then
  5150.         _filedir '@(py|pyc|pyo)'
  5151.     else
  5152.         COMPREPLY=( $( compgen -W "- -d -E -h -i -O -Q -S -t -u \
  5153.                        -U -v -V -W -x -c" -- $cur ) )
  5154.     fi
  5155.  
  5156.  
  5157.  
  5158.     return 0
  5159. } &&
  5160. complete -F _python $filenames python
  5161.  
  5162. # Perl completion
  5163. #
  5164. have perl &&
  5165. {
  5166. _perlmodules()
  5167. {
  5168.     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 ) )
  5169. }
  5170.  
  5171. _perl()
  5172. {
  5173.     local cur prev prefix temp
  5174.  
  5175.     COMPREPLY=()
  5176.     cur=${COMP_WORDS[COMP_CWORD]}
  5177.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5178.     prefix=""
  5179.  
  5180.     # completing an option (may or may not be separated by a space)
  5181.     if [[ "$cur" == -?* ]]; then
  5182.     temp=$cur
  5183.     prev=${temp:0:2}
  5184.     cur=${temp:2}
  5185.     prefix=$prev
  5186.     fi
  5187.  
  5188.     # only handle module completion for now
  5189.     case "$prev" in
  5190.     -m|-M)
  5191.         _perlmodules
  5192.         return 0
  5193.         ;;
  5194.     esac
  5195.  
  5196.     # handle case where first parameter is not a dash option
  5197.     if [ $COMP_CWORD -eq 1 ] && [[ "$cur" != -* ]]; then
  5198.     _filedir
  5199.     return 0
  5200.     fi
  5201.  
  5202.     # complete using basic options
  5203.     COMPREPLY=( $( compgen -W '-C -s -T -u -U -W -X -h -v -V -c -w -d -D -p \
  5204.             -n -a -F -l -0 -I -m -M -P -S -x -i -e ' -- $cur ) )
  5205.     return 0
  5206. }
  5207. complete -F _perl $filenames perl
  5208.  
  5209. _perldoc()
  5210. {
  5211.     local cur prev prefix temp
  5212.  
  5213.     COMPREPLY=()
  5214.     cur=${COMP_WORDS[COMP_CWORD]}
  5215.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5216.     prefix=""
  5217.  
  5218.     # completing an option (may or may not be separated by a space)
  5219.     if [[ "$cur" == -?* ]]; then
  5220.     temp=$cur
  5221.     prev=${temp:0:2}
  5222.     cur=${temp:2}
  5223.     prefix=$prev
  5224.     fi
  5225.  
  5226.     # complete builtin perl functions
  5227.     case $prev in
  5228.     -f)
  5229.         COMPREPLY=( $( compgen -W 'chomp chop chr crypt hex index lc \
  5230.         lcfirst length oct ord pack q qq reverse rindex sprintf \
  5231.         substr tr uc ucfirst y m pos quotemeta s split study qr abs \
  5232.         atan2 cos exp hex int log oct rand sin sqrt srand pop push \
  5233.         shift splice unshift grep join map qw reverse sort unpack \
  5234.         delete each exists keys values binmode close closedir \
  5235.         dbmclose dbmopen die eof fileno flock format getc print \
  5236.         printf read readdir rewinddir seek seekdir select syscall \
  5237.         sysread sysseek syswrite tell telldir truncate warn write \
  5238.         pack read syscall sysread syswrite unpack vec -X chdir chmod \
  5239.         chown chroot fcntl glob ioctl link lstat mkdir open opendir \
  5240.         readlink rename rmdir stat symlink umask unlink utime caller \
  5241.         continue do dump eval exit goto last next redo return \
  5242.         sub wantarray caller import local my our package use defined \
  5243.         formline reset scalar undef \
  5244.         alarm exec fork getpgrp getppid getpriority kill pipe qx \
  5245.         setpgrp setpriority sleep system times wait waitpid \
  5246.         import no package require use bless dbmclose dbmopen package \
  5247.         ref tie tied untie use accept bind connect getpeername \
  5248.         getsockname getsockopt listen recv send setsockopt shutdown \
  5249.         socket socketpair msgctl msgget msgrcv msgsnd semctl semget \
  5250.         semop shmctl shmget shmread shmwrite endgrent endhostent \
  5251.         endnetent endpwent getgrent getgrgid getgrnam getlogin \
  5252.         getpwent getpwnam getpwuid setgrent setpwent endprotoent \
  5253.         endservent gethostbyaddr gethostbyname gethostent \
  5254.         getnetbyaddr getnetbyname getnetent getprotobyname \
  5255.         getprotobynumber getprotoent getservbyname getservbyport \
  5256.         getservent sethostent setnetent setprotoent setservent \
  5257.         gmtime localtime time times' -- $cur ) )
  5258.         return 0
  5259.         ;;
  5260.     esac
  5261.  
  5262.     case $cur in
  5263.     -*)
  5264.         COMPREPLY=( $( compgen -W '-h -v -t -u -m -l -F -X -f -q' -- $cur ))
  5265.         return 0
  5266.         ;;
  5267.     */*)
  5268.         return 0
  5269.         ;;
  5270.     *)
  5271.         _perlmodules
  5272.         COMPREPLY=( ${COMPREPLY[@]} $( compgen -W '$( PAGER=cat man perl 2>/dev/null | sed -ne "/perl.*Perl overview/,/perlwin32/s/^[^a-z0-9]*\([a-z0-9]*\).*$/\1/p")' -- $cur ) )
  5273.  
  5274.         return 0
  5275.         ;;
  5276.     esac
  5277. }
  5278. complete -F _perldoc $default perldoc
  5279. }
  5280.  
  5281. # rcs(1) completion
  5282. #
  5283. have rcs &&
  5284. _rcs()
  5285. {
  5286.     local cur prev file dir i
  5287.  
  5288.     COMPREPLY=()
  5289.     cur=${COMP_WORDS[COMP_CWORD]}
  5290.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5291.  
  5292.     file=${cur##*/}
  5293.     dir=${cur%/*}
  5294.  
  5295.     # deal with relative directory
  5296.     [ "$file" = "$dir" ] && dir=.
  5297.  
  5298.     COMPREPLY=( $( compgen -f "$dir/RCS/$file" ) )
  5299.  
  5300.     for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
  5301.         file=${COMPREPLY[$i]##*/}
  5302.         dir=${COMPREPLY[$i]%RCS/*}
  5303.         COMPREPLY[$i]=$dir$file
  5304.     done
  5305.     
  5306.     COMPREPLY=( "${COMPREPLY[@]}" $( compgen -G "$dir/$file*,v" ) )
  5307.  
  5308.     for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
  5309.         COMPREPLY[$i]=${COMPREPLY[$i]%,v}
  5310.     done
  5311.  
  5312.     # default to files if nothing returned and we're checking in.
  5313.     # otherwise, default to directories
  5314.     [ ${#COMPREPLY[@]} -eq 0 -a $1 = ci ] && _filedir || _filedir -d
  5315. } &&
  5316. complete -F _rcs $filenames ci co rlog rcs rcsdiff
  5317.  
  5318. # lilo(8) completion
  5319. #
  5320. have lilo && {
  5321. _lilo_labels()
  5322. {
  5323.     COMPREPLY=( $( awk -F'=' '/label/ {print $2}' \
  5324.         /etc/lilo.conf | sed -e 's/"//g' | grep "^$cur" ) )
  5325. }
  5326.  
  5327. _lilo()
  5328. {
  5329.     local cur prev
  5330.  
  5331.     COMPREPLY=()
  5332.     cur=${COMP_WORDS[COMP_CWORD]}
  5333.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5334.  
  5335.     case $prev in
  5336.         -@(C|i|m|s|S))
  5337.             _filedir
  5338.             return 0
  5339.             ;;
  5340.         -r)
  5341.             _filedir -d
  5342.             return 0
  5343.             ;;
  5344.         -@(I|D|R))
  5345.             # label completion
  5346.             _lilo_labels
  5347.             return 0
  5348.             ;;
  5349.         -@(A|b|M|u|U))
  5350.             # device completion
  5351.             cur=${cur:=/dev/}
  5352.             _filedir
  5353.             return 0
  5354.             ;;
  5355.         -T)
  5356.             # topic completion
  5357.             COMPREPLY=( $( compgen -W 'help ChRul EBDA geom geom= \
  5358.                     table= video' -- $cur ) )
  5359.             return 0
  5360.             ;;
  5361.     esac
  5362.  
  5363.     if [[ "$cur" == -* ]]; then
  5364.         # relevant options completion
  5365.         COMPREPLY=( $( compgen -W '-A -b -c -C -d -f -g -i -I -l -L -m \
  5366.             -M -p -P -q -r -R -s -S -t -T -u -U -v -V -w -x -z' -- \
  5367.             $cur ) )
  5368.     fi
  5369. }
  5370. complete -F _lilo lilo
  5371. }
  5372.  
  5373. # links completion
  5374. #
  5375. have links &&
  5376. _links()
  5377. {
  5378.     local cur
  5379.   
  5380.     COMPREPLY=()
  5381.     cur=${COMP_WORDS[COMP_CWORD]}
  5382.   
  5383.     case "$cur" in
  5384.         --*)
  5385.         COMPREPLY=( $( compgen -W '--help' -- $cur ) )
  5386.         ;;
  5387.         -*)
  5388.         COMPREPLY=( $( compgen -W '-async-dns -max-connections \
  5389.                 -max-connections-to-host -retries \
  5390.                 -receive-timeout -unrestartable-receive-timeout\
  5391.                 -format-cache-size -memory-cache-size \
  5392.                 -http-proxy -ftp-proxy -download-dir \
  5393.                 -assume-codepage -anonymous -dump -no-connect \
  5394.                 -source -version -help' -- $cur ) )
  5395.         ;;
  5396.         *)
  5397.         if [ -r ~/.links/links.his ]; then
  5398.             COMPREPLY=( $( compgen -W '$( < ~/.links/links.his )' \
  5399.                    -- $cur ) )
  5400.         fi
  5401.                 _filedir '@(htm|html)'
  5402.                 return 0
  5403.         ;;
  5404.     esac
  5405.   
  5406.     return 0
  5407. } &&
  5408. complete -F _links $filenames links
  5409.  
  5410. [ $UNAME = FreeBSD ] && {
  5411. # FreeBSD package management tool completion
  5412. #
  5413. _pkg_delete()
  5414. {
  5415.     local cur pkgdir prev
  5416.  
  5417.     pkgdir=${PKG_DBDIR:-/var/db/pkg}/
  5418.     cur=${COMP_WORDS[COMP_CWORD]}
  5419.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5420.  
  5421.     [ "$prev" = "-o" -o "$prev" = "-p" -o "$prev" = "-W" ] && return 0
  5422.  
  5423.     COMPREPLY=( $( compgen -d $pkgdir$cur ) )
  5424.     COMPREPLY=( ${COMPREPLY[@]#$pkgdir} )
  5425.  
  5426.     return 0
  5427. }
  5428. complete -F _pkg_delete $dirnames pkg_delete pkg_info
  5429. have pkg_deinstall && complete -F _pkg_delete $dirnames pkg_deinstall
  5430.  
  5431. # FreeBSD kernel module commands
  5432. #
  5433. _kldload()
  5434. {
  5435.     local cur moddir
  5436.  
  5437.     moddir=/modules/
  5438.     [ -d $moddir ] || moddir=/boot/kernel/
  5439.     cur=${COMP_WORDS[COMP_CWORD]}
  5440.  
  5441.     COMPREPLY=( $( compgen -f $moddir$cur ) )
  5442.     COMPREPLY=( ${COMPREPLY[@]#$moddir} )
  5443.     COMPREPLY=( ${COMPREPLY[@]%.ko} )
  5444.  
  5445.     return 0
  5446. }
  5447. complete -F _kldload $filenames kldload
  5448.  
  5449. _kldunload()
  5450. {
  5451.     local cur
  5452.     cur=${COMP_WORDS[COMP_CWORD]}
  5453.     COMPREPLY=( $(kldstat | sed -ne "s/^.*[ \t]\+\($cur[a-z_]\+\).ko$/\1/p") )
  5454. }
  5455. complete -F _kldunload $filenames kldunload
  5456. }
  5457.  
  5458. # FreeBSD portupgrade completion
  5459. #
  5460. have portupgrade &&
  5461. _portupgrade()
  5462. {
  5463.     local cur pkgdir prev
  5464.  
  5465.     pkgdir=${PKG_DBDIR:-/var/db/pkg}/
  5466.     cur=${COMP_WORDS[COMP_CWORD]}
  5467.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5468.  
  5469.     [ "$prev" = "-l" -o "$prev" = "-L" -o "$prev" = "-o" ] && return 0
  5470.  
  5471.     COMPREPLY=( $( compgen -d $pkgdir$cur ) )
  5472.     COMPREPLY=( ${COMPREPLY[@]#$pkgdir} )
  5473.     COMPREPLY=( ${COMPREPLY[@]%-*} )
  5474.  
  5475.     return 0
  5476. } &&
  5477. complete -F _portupgrade $dirnames portupgrade
  5478.  
  5479. # FreeBSD portinstall completion
  5480. #
  5481. have portinstall &&
  5482. _portinstall()
  5483. {
  5484.     local cur portsdir prev indexfile
  5485.     local -a COMPREPLY2
  5486.  
  5487.     portsdir=${PORTSDIR:-/usr/ports}/
  5488.     cur=${COMP_WORDS[COMP_CWORD]}
  5489.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5490.     # First try INDEX-5
  5491.     indexfile=$portsdir/INDEX-5
  5492.     # Then INDEX if INDEX-5 does not exist or system is not FreeBSD 5.x
  5493.     [ "${OSTYPE%.*}" = "freebsd5" -a -f $indexfile ] ||
  5494.       indexfile=$portsdir/INDEX
  5495.  
  5496.     [ "$prev" = "-l" -o "$prev" = "-L" -o "$prev" = "-o" ] && return 0
  5497.  
  5498.     COMPREPLY=( $( egrep "^$cur" < $indexfile | cut -d'|' -f1 ) )
  5499.     COMPREPLY2=( $( egrep "^[^\|]+\|$portsdir$cur" < $indexfile | \
  5500.             cut -d'|' -f2 ) )
  5501.     COMPREPLY2=( ${COMPREPLY2[@]#$portsdir} )
  5502.     COMPREPLY=( ${COMPREPLY[@]} ${COMPREPLY2[@]} )
  5503.  
  5504.     return 0
  5505. } &&
  5506. complete -F _portinstall $dirnames portinstall
  5507.  
  5508. # Slackware Linux removepkg completion
  5509. #
  5510. have removepkg && [ -f /etc/slackware-version ] &&
  5511. _removepkg()
  5512. {
  5513.     local packages cur
  5514.  
  5515.     COMPREPLY=()
  5516.     cur=${COMP_WORDS[COMP_CWORD]}
  5517.  
  5518.     COMPREPLY=( $( (cd /var/log/packages; compgen -f -- "$cur") ) )
  5519. } &&
  5520. complete -F _removepkg $filenames removepkg &&
  5521.     complete $dirnames -f -X '!*.tgz' installpkg upgradepkg explodepkg
  5522.  
  5523. # look(1) completion
  5524. #
  5525. have look && 
  5526. _look()
  5527. {
  5528.     local cur
  5529.   
  5530.     COMPREPLY=()
  5531.     cur=${COMP_WORDS[COMP_CWORD]}
  5532.  
  5533.     if [ $COMP_CWORD = 1 ]; then
  5534.         COMPREPLY=( $( compgen -W '$(look $cur)' ) )
  5535.     fi
  5536. } &&
  5537. complete -F _look $default look
  5538.  
  5539. # ypcat(1) and ypmatch(1) completion
  5540. #
  5541. have ypmatch &&
  5542. _ypmatch()
  5543. {
  5544.     local cur map
  5545.  
  5546.     COMPREPLY=()
  5547.     cur=${COMP_WORDS[COMP_CWORD]}
  5548.  
  5549.     [ $1 = ypcat ] && [ $COMP_CWORD -gt 1 ] && return 0
  5550.     [ $1 = ypmatch ] && [ $COMP_CWORD -gt 2 ] && return 0
  5551.  
  5552.     if [ $1 = ypmatch ] && [ $COMP_CWORD -eq 1 ] && \
  5553.        [ ${#COMP_WORDS[@]} -eq 3 ]; then
  5554.         map=${COMP_WORDS[2]}
  5555.         COMPREPLY=( $( compgen -W '$( ypcat $map | \
  5556.                         cut -d':' -f 1 )' -- $cur) )
  5557.     else
  5558.         [ $1 = ypmatch ] && [ $COMP_CWORD -ne 2 ] && return 0
  5559.         COMPREPLY=( $( compgen -W \
  5560.                   '$( echo $(ypcat -x | cut -d"\"" -f 2))' -- $cur))
  5561.     fi
  5562.  
  5563.     return 0
  5564. } &&
  5565. complete -F _ypmatch ypmatch ypcat
  5566.  
  5567. # mplayer(1) completion
  5568. #
  5569. have mplayer && {
  5570. _mplayer_options_list()
  5571. {
  5572.     cur=${cur%\\}
  5573.     COMPREPLY=( $( $1 $2 help 2> /dev/null | \
  5574.         sed -e '1,/^Available/d' | awk '{print $1}' | \
  5575.         sed -e 's/:$//' -e 's/^'${2#-}'$//' -e 's/<.*//' | \
  5576.         grep "^$cur" ) )
  5577. }
  5578.  
  5579. _mplayer()
  5580. {
  5581.     local cmd cur prev skinsdir IFS=$' \t\n' i j k=0
  5582.  
  5583.     COMPREPLY=()
  5584.     cmd=${COMP_WORDS[0]}
  5585.     cur=${COMP_WORDS[COMP_CWORD]}
  5586.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5587.  
  5588.     case "$prev" in
  5589.         -@(ac|afm|vc|vfm|ao|vo|vop|fstype))
  5590.             _mplayer_options_list mplayer $prev
  5591.             return 0
  5592.             ;;
  5593.         -@(oac|ovc|of))
  5594.             _mplayer_options_list mencoder $prev
  5595.             return 0
  5596.             ;;
  5597.         -audiofile)
  5598.             _filedir '@(mp3|MP3|mpg|MPG|ogg|OGG|wav|WAV|mid|MID)'
  5599.             return 0
  5600.             ;;
  5601.         -font)
  5602.             _filedir '@(desc|ttf)'
  5603.             return 0
  5604.             ;;
  5605.         -sub)
  5606.             _filedir '@(srt|SRT|sub|SUB|txt|TXT|utf|UTF|rar|RAR|mpsub|smi|js)'
  5607.             return 0
  5608.             ;;
  5609.         -vobsub)
  5610.             _filedir '@(idx|IDX|ifo|IFO|sub|SUB)'
  5611.             IFS=$'\t\n' 
  5612.             COMPREPLY=( $( for i in ${COMPREPLY[@]}; do
  5613.                         if [ -f $i -a -r $i ]; then
  5614.                             echo ${i%.*}
  5615.                         else
  5616.                             echo $i
  5617.                         fi
  5618.                        done ) )
  5619.             IFS=$' \t\n' 
  5620.             return 0
  5621.             ;;
  5622.         -ifo)
  5623.             _filedir '@(ifo|IFO)'
  5624.             return 0
  5625.             ;;
  5626.         -cuefile)
  5627.             _filedir '@(bin|BIN|cue|CUE)'
  5628.             return 0
  5629.             ;;
  5630.         -skin)
  5631.             # if you don't have installed mplayer in /usr/local you
  5632.             # may want to set the MPLAYER_SKINS_DIR global variable
  5633.             if [ -n "$MPLAYER_SKINS_DIR" ]; then
  5634.                 skinsdir=$MPLAYER_SKINS_DIR
  5635.             else
  5636.                 skinsdir=/usr/local/share/mplayer/Skin
  5637.             fi
  5638.  
  5639.             IFS=$'\t\n' 
  5640.             for i in ~/.mplayer/Skin $skinsdir; do
  5641.                 if [ -d $i -a -r $i ]; then
  5642.                     for j in $( compgen -d $i/$cur ); do
  5643.                         COMPREPLY[$k]=${j#$i/}
  5644.                         k=$((++k))
  5645.                     done
  5646.                 fi
  5647.             done
  5648.             IFS=$' \t\n' 
  5649.             return 0
  5650.             ;;
  5651.         -@(mixer|@(cdrom|dvd)-device|dvdauth|fb|zrdev))
  5652.             cur=${cur:=/dev/}
  5653.             _filedir
  5654.             return 0
  5655.             ;;
  5656.         -@(edl?(out)|lircconf|menu-cfg|playlist|csslib|dumpfile)| \
  5657.         -@(subfile|vobsub|aofile|fbmodeconfig|include|o|dvdkey)| \
  5658.         -passlogfile)
  5659.             _filedir
  5660.             return 0
  5661.             ;;
  5662.         -@(auto@(q|sync)|loop|menu-root|speed|sstep|aid|alang)| \
  5663.         -@(?(@(audio|sub)-)demuxer|bandwidth|cache|chapter)| \
  5664.         -@(dvd?(angle)|fps|frames|mc|passwd|user|sb|srate|ss|vcd)| \
  5665.         -@(vi?(d|vo)|ffactor|sid|slang|spu@(align|aa|gauss))| \
  5666.         -@(vobsubid|delay|bpp|brightness|contrast|dfbopts|display)| \
  5667.         -@(fbmode|geometry|guiwid|hue|icelayer|screen[wh]|wid)| \
  5668.         -@(monitor@(aspect|-@(dotclock|[hv]freq))|panscan|saturation)| \
  5669.         -@(xineramascreen|zr@(crop|norm|quality|[xy]doff|[vh]dec))| \
  5670.         -@(aspect|pp|x|y|xy|z|stereo|audio-@(density|delay|preload))| \
  5671.         -@(endpos|osdlevel|ffourcc|sws|channels|skiplimit|format)| \
  5672.         -@(ofps|aa@(driver|@(osd|sub)color)|vobsubout?(i@(ndex|d)))| \
  5673.         -sub@(-bg-@(alpha|color)|cp|delay|fps|pos|align|width)| \
  5674.         -sub@(font-@(blur|outline|autoscale|encoding|@(osd|text)-scale)))
  5675.             return 0
  5676.             ;;
  5677.         -lavdopts)
  5678.             COMPREPLY=( $( compgen -W 'ec er= bug= idct= gray' \
  5679.                     -- $cur ) )
  5680.             return 0
  5681.             ;;
  5682.         -lavcopts)
  5683.             COMPREPLY=( $( compgen -W 'vcodec= vqmin= vqscale= \
  5684.                     vqmax= mbqmin= mbqmax= vqdiff= \
  5685.                     vmax_b_frames= vme= vhq v4mv \
  5686.                     keyint= vb_strategy= vpass= \
  5687.                     aspect= vbitrate= vratetol= \
  5688.                     vrc_maxrate= vrc_minrate= \
  5689.                     vrc_buf_size= vb_qfactor= vi_qfactor= \
  5690.                     vb_qoffset= vi_qoffset= vqblur= \
  5691.                     vqcomp= vrc_eq= vrc_override= \
  5692.                     vrc_init_cplx= vqsquish= vlelim= \
  5693.                     vcelim= vstrict= vdpart vpsize= gray \
  5694.                     vfdct= idct= lumi_mask= dark_mask= \
  5695.                     tcplx_mask= scplx_mask= naq ildct \
  5696.                     format= pred qpel precmp= cmp= \
  5697.                     subcmp= predia= dia= trell last_pred= \
  5698.                     preme= subq= psnr mpeg_quant aic umv' \
  5699.                     -- $cur ) )
  5700.             return 0
  5701.             ;;
  5702.         -ssf)
  5703.             COMPREPLY=( $( compgen -W 'lgb= cgb= ls= cs= chs= \
  5704.                     cvs=' -- $cur ) )
  5705.             return 0
  5706.             ;;
  5707.         -jpeg)
  5708.             COMPREPLY=( $( compgen -W 'noprogressive progressive \
  5709.                     nobaseline baseline optimize= \
  5710.                     smooth= quality= outdir=' -- $cur ) )
  5711.             return 0
  5712.             ;;
  5713.         -xvidopts)
  5714.             COMPREPLY=( $( compgen -W 'dr2 nodr2' -- $cur ) )
  5715.             return 0
  5716.             ;;
  5717.         -xvidencopts)
  5718.             COMPREPLY=( $( compgen -W 'pass= bitrate= \
  5719.                     fixed_quant= me_quality= 4mv \
  5720.                     rc_reaction_delay_factor= \
  5721.                     rc_averaging_period= rc_buffer= \
  5722.                     quant_range= min_key_interval= \
  5723.                     max_key_interval= mpeg_quant \
  5724.                     mod_quant lumi_mask hintedme \
  5725.                     hintfile debug keyframe_boost= \
  5726.                     kfthreshold= kfreduction=' -- $cur ) )
  5727.             return 0
  5728.             ;;
  5729.         -divx4opts)
  5730.             COMPREPLY=( $( compgen -W 'br= key= deinterlace q= \
  5731.                     min_quant= max_quant= rc_period= \
  5732.                     rc_reaction_period= crispness= \
  5733.                     rc_reaction_ratio= pass= vbrpass= \
  5734.                     help' -- $cur ) )
  5735.             return 0
  5736.             ;;
  5737.         -info)
  5738.             COMPREPLY=( $( compgen -W 'name= artist= genre= \
  5739.                     subject= copyright= srcform= \
  5740.                     comment= help' -- $cur ) )
  5741.             return 0
  5742.             ;;
  5743.         -lameopts)
  5744.             COMPREPLY=( $( compgen -W 'vbr= abr cbr br= q= aq= \
  5745.                     ratio= vol= mode= padding= fast \
  5746.                     preset= help' -- $cur ) )
  5747.             return 0
  5748.             ;;
  5749.         -rawaudio)
  5750.             COMPREPLY=( $( compgen -W 'on channels= rate= \
  5751.                     samplesize= format=' -- $cur ) )
  5752.             return 0
  5753.             ;;
  5754.         -rawvideo)
  5755.             COMPREPLY=( $( compgen -W 'on fps= sqcif qcif cif \
  5756.                     4cif pal ntsc w= h= y420 yv12 yuy2 \
  5757.                     y8 format= size=' -- $cur ) )
  5758.             return 0
  5759.             ;;
  5760.         -aop)
  5761.             COMPREPLY=( $( compgen -W 'list= delay= format= fout= \
  5762.                     volume= mul= softclip' -- $cur ) )
  5763.             return 0
  5764.             ;;
  5765.         -dxr2)
  5766.             COMPREPLY=( $( compgen -W 'ar-mode= iec958-encoded \
  5767.                     iec958-decoded mute ucode= 75ire bw \
  5768.                     color interlaced macrovision= norm= \
  5769.                     square-pixel ccir601-pixel cr-left= \
  5770.                     cr-right= cr-top= cr-bot= ck-rmin= \
  5771.                     ck-gmin= ck-bmin= ck-rmax= ck-gmax= \
  5772.                     ck-bmax= ck-r= ck-g= ck-b= \
  5773.                     ignore-cache= ol-osd= olh-cor= \
  5774.                     olw-cor= olx-cor= oly-cor= overlay \
  5775.                     overlay-ratio= update-cache' -- $cur ))
  5776.             return 0
  5777.             ;;
  5778.         -tv)
  5779.             COMPREPLY=( $( compgen -W 'on noaudio driver= device= \
  5780.                     input= freq= outfmt= width= height= \
  5781.                     buffersize= norm= channel= chanlist= \
  5782.                     audiorate= forceaudio alsa amode= \
  5783.                     forcechan= adevice= audioid= volume= \
  5784.                     bass= treble= balance= fps= \
  5785.                     channels= immediatemode=' -- $cur ) )
  5786.             return 0
  5787.             ;;
  5788.         -mf)
  5789.             COMPREPLY=( $( compgen -W 'on w= h= fps= type=' \
  5790.                     -- $cur ) )
  5791.             return 0
  5792.             ;;
  5793.         -cdda)
  5794.             COMPREPLY=( $( compgen -W 'speed= paranoia= \
  5795.                     generic-dev= sector-size= overlap= \
  5796.                     toc-bias toc-offset= skip noskip' \
  5797.                     -- $cur ) )
  5798.             return 0
  5799.             ;;
  5800.         -input)
  5801.             COMPREPLY=( $( compgen -W 'conf= ar-delay ar-rate \
  5802.                     keylist cmdlist js-dev file' -- $cur ) )
  5803.             return 0
  5804.             ;;
  5805.         -af)
  5806.             COMPREPLY=( $( compgen -W 'resample resample= \
  5807.                     channels channels= format format= \
  5808.                     volume volume= delay delay= pan \
  5809.                     pan= sub sub= surround surround=' \
  5810.                     -- $cur ) )
  5811.             return 0
  5812.             ;;
  5813.         -af-adv)
  5814.             COMPREPLY=( $( compgen -W 'force= list=' -- $cur ) )
  5815.             return 0
  5816.             ;;
  5817.     esac
  5818.  
  5819.     case "$cur" in
  5820.         -*)
  5821.             COMPREPLY=( $( compgen -W '-aid -alang -audio-demuxer \
  5822.                     -audiofile -cdrom-device -cache -cdda \
  5823.                     -channels -chapter -csslib -demuxer \
  5824.                     -dvd -dvd-device -dvdangle -dvdauth \
  5825.                     -dvdkey -dvdnav -forceidx -fps -frames \
  5826.                     -hr-mp3-seek -idx -mc -mf -ni -nobps \
  5827.                     -passwd -rawaudio -rtsp-stream-over-tcp\
  5828.                     -skipopening -sb -srate -ss -tv -user \
  5829.                     -vcd -vid -vivo -ifo -ffactor -font \
  5830.                     -noautosub -nooverlapsub -sid -slang \
  5831.                     -sub -subcc -subcp -sub-demuxer \
  5832.                     -subdelay -subfont-autoscale \
  5833.                     -subfont-blur -subfont-encoding \
  5834.                     -subfont-osd-scale -subfont-outline \
  5835.                     -subfont-text-scale -subfps -subfile \
  5836.                     -subpos -unicode -utf8 -vobsub \
  5837.                     -vobsubid -ac -afm -aspect -flip \
  5838.                     -lavdopts -noaspect -nosound -pp -ssf \
  5839.                     -stereo -sws -vc -vfm -vop -xvidopts\
  5840.                     -xy -zoom -bandwidth -cuefile \
  5841.                     -noextbased -rawvideo -overlapsub \
  5842.                     -sub-bg-alpha -sub-bg-color -subalign \
  5843.                     -subwidth -sub-no-text-pp -spualign \
  5844.                     -spuaa -spugauss -pphelp -verbose -v \
  5845.                     -noni -noidx -nohr-mp3-seek -extbased \
  5846.                     -bps -oldpp -nozoom -noflip -nounicode \
  5847.                     -noutf8' -- $cur ) )
  5848.             # add mplayer specific options
  5849.             [[ "$cmd" == @(?(g)mplayer) ]] && COMPREPLY=( ${COMPREPLY[@]} \
  5850.                 $(compgen -W '-autoq -autosync -benchmark \
  5851.                     -framedrop -h -help -hardframedrop \
  5852.                     -identify -input -lircconf -loop \
  5853.                     -nojoystick -nolirc -nortc -playlist \
  5854.                     -quiet -really-quiet -rnd -sdp -skin \
  5855.                     -slave -softsleep -speed -sstep \
  5856.                     -use-stdin -dumpaudio -dumpfile \
  5857.                     -dumpstream -dumpvideo -dumpmicrodvdsub\
  5858.                     -dumpmpsub -dumpsrtsub -dumpjacosub \
  5859.                     -dumpsami -dumpsub -osdlevel -af \
  5860.                     -af-adv -ao -aofile -aop -delay -mixer \
  5861.                     -nowaveheader -bpp -brightness \
  5862.                     -contrast -display -double -dr -dxr2 \
  5863.                     -fb -fbmode -fbmodeconfig -forcexv -fs \
  5864.                     -geometry -hue -icelayer -jpeg \
  5865.                     -monitor-dotclock -monitor-hfreq \
  5866.                     -monitor-vfreq -monitoraspect \
  5867.                     -nograbpointer -noslices -panscan \
  5868.                     -rootwin -saturation -screenw -screenh \
  5869.                     -stop-xscreensaver -vm -vo -vsync -wid \
  5870.                     -xineramascreen -z -zrbw -zrcrop \
  5871.                     -zrdev -zrfd -zrhelp -zrnorm -zrquality \
  5872.                     -zrvdec -zrhdec -zrxdoff -zrydoff -y \
  5873.                     -edl -edlout -enqueue -fixed-vo \
  5874.                     -menu -menu-root -menu-cfg -shuffle \
  5875.                     -format -aahelp -dfbopts -fstype \
  5876.                     -guiwid -nokeepaspect -x --help \
  5877.                     -aaosdcolor -aasubcolor -aadriver \
  5878.                     -aaextended -aaeight' -- $cur) )
  5879.             # add mencoder specific options
  5880.             [[ "$cmd" = mencoder ]] && COMPREPLY=( ${COMPREPLY[@]} \
  5881.                 $(compgen -W '-audio-density -audio-delay \
  5882.                     -audio-preload -divx4opts -endpos \
  5883.                     -ffourcc -include -info -lameopts \
  5884.                     -lavcopts -noskip -o -oac -ofps -ovc \
  5885.                     -passlogfile -skiplimit -vobsubout \
  5886.                     -vobsuboutindex -vobsuboutid \
  5887.                     -xvidencopts -of --verbose' -- $cur) )
  5888.             ;;
  5889.         *)
  5890.             _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|fli|FLI|viv|VIV|rm?(j)|RM?(J)|ra?(m)|RA?(M)|yuv|YUV|mov|MOV|qt|QT|mp[34]|MP[34]|og[gm]|OG[GM]|wav|WAV|dump|DUMP|mkv|MKV|m4a|M4A|aac|AAC|m2v|M2V|dv|DV|rmvb|RMVB|mid|MID|ts|TS|3gp|mpc|MPC|flac|FLAC|flv|FLV)'
  5891.             ;;
  5892.     esac
  5893.  
  5894.     return 0
  5895. }
  5896. complete $filenames -F _mplayer mplayer mencoder gmplayer kplayer
  5897. }
  5898.  
  5899. # KDE dcop completion
  5900. #
  5901. have dcop &&
  5902. _dcop()
  5903. {
  5904.     local cur compstr
  5905.  
  5906.     COMPREPLY=()
  5907.     cur=${COMP_WORDS[COMP_CWORD]}
  5908.     if [ -z $cur ]; then
  5909.         compstr=${COMP_WORDS[*]}
  5910.     else
  5911.         compstr=$( command echo ${COMP_WORDS[*]} | sed "s/ $cur$//" )
  5912.     fi
  5913.     COMPREPLY=( $( compgen -W '$( command $compstr | sed s/\(.*\)// )'  -- $cur ) )
  5914. } &&
  5915. complete -F _dcop dcop
  5916.  
  5917. # wvdial(1) completion
  5918. #
  5919. have wvdial &&
  5920. _wvdial()
  5921. {
  5922.     local cur prev config i IFS=$'\t\n'
  5923.  
  5924.     COMPREPLY=()
  5925.     cur=${COMP_WORDS[COMP_CWORD]}
  5926.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5927.  
  5928.     case $prev in
  5929.         --config)
  5930.             _filedir
  5931.             return 0
  5932.             ;;
  5933.     esac
  5934.  
  5935.     case $cur in
  5936.         -*)
  5937.             COMPREPLY=( $( compgen -W '--config --chat \
  5938.                 --remotename --help --version --no-syslog' \
  5939.                 -- $cur ) )
  5940.             ;;
  5941.         *)
  5942.             # start with global and personal config files
  5943.                    config="/etc/wvdial.conf"$'\t'"$HOME/.wvdialrc"
  5944.             # replace with command line config file if present
  5945.             for (( i=1; i < COMP_CWORD; i++ )); do
  5946.                 if [[ "${COMP_WORDS[i]}" == "--config" ]]; then
  5947.                     config=${COMP_WORDS[i+1]}
  5948.                     break
  5949.                 fi
  5950.             done
  5951.             # parse config files for sections and
  5952.             # remove default section
  5953.             COMPREPLY=( $( sed -ne \
  5954.                     "s|^\[Dialer \($cur.*\)\]$|\1|p" \
  5955.                     $config 2>/dev/null |grep -v '^Defaults$'))
  5956.             # escape spaces
  5957.             COMPREPLY=${COMPREPLY// /\\ }
  5958.             ;;
  5959.     esac
  5960.  
  5961. } &&
  5962. complete -F _wvdial wvdial
  5963.  
  5964. # gpg(1) completion
  5965. #
  5966. have gpg &&
  5967. _gpg() 
  5968. {
  5969.     local cur prev
  5970.  
  5971.     COMPREPLY=()
  5972.     cur=${COMP_WORDS[COMP_CWORD]}
  5973.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5974.  
  5975.     case "$prev" in
  5976.     -@(s|-sign|-clearsign|-decrypt-files|-load-extension)) 
  5977.         _filedir
  5978.         return 0
  5979.         ;;
  5980.     --@(export|@(?(l|nr|nrl)sign|edit)-key)) 
  5981.         # return list of public keys
  5982.         COMPREPLY=( $( compgen -W "$( gpg --list-keys 2>/dev/null | sed -ne 's@^pub.*/\([^ ]*\).*\(<\([^>]*\)>\).*$@\1 \3@p')" -- "$cur" ))
  5983.         return 0
  5984.         ;;
  5985.     -@(r|-recipient))
  5986.         COMPREPLY=( $( compgen -W "$( gpg --list-keys 2>/dev/null | sed -ne 's@^pub.*<\([^>]*\)>.*$@\1@p')" -- "$cur" ))
  5987.         if [ -e ~/.gnupg/gpg.conf ]; then
  5988.             COMPREPLY=( ${COMPREPLY[@]} $( compgen -W "$( sed -ne 's@^[ \t]*group[ \t][ \t]*\([^=]*\).*$@\1@p' ~/.gnupg/gpg.conf  )" -- "$cur") )
  5989.         fi
  5990.         return 0
  5991.         ;;
  5992.     esac
  5993.  
  5994.     if [[ "$cur" == -* ]]; then
  5995.         COMPREPLY=( $( compgen -W '-s -b -e -f -c -d -a -r -u -Z -o -v\
  5996.                 -q -n -N $(gpg --dump-options)' -- $cur ) )
  5997.      fi
  5998.  
  5999. } &&
  6000. complete -F _gpg $default gpg
  6001.  
  6002. # iconv(1) completion
  6003. #
  6004. have iconv &&
  6005. _iconv()
  6006. {
  6007.     local cur prev
  6008.  
  6009.     COMPREPLY=()
  6010.     cur=${COMP_WORDS[COMP_CWORD]}
  6011.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6012.  
  6013.     case "$prev" in
  6014.         -@(f|t|-@(from|to)-code))
  6015.             COMPREPLY=( $( compgen -W \
  6016.                 '$( iconv --list | sed -e "s@//@@;" )' -- "$cur" ) )
  6017.             return 0
  6018.             ;;
  6019.     esac
  6020.  
  6021.  
  6022.     if [[ "$cur" = -* ]]; then
  6023.         COMPREPLY=( $( compgen -W '--from-code -f --to-code -t --list
  6024.         --output -o --verbose' -- "$cur" ) )
  6025.         return 0
  6026.     fi
  6027. } &&
  6028. complete -F _iconv $default iconv
  6029.  
  6030. # dict(1) completion
  6031. #
  6032. { have dict || have rdict; } && {
  6033. _dictdata()
  6034. {
  6035.     dict $host $port $1 2>/dev/null | sed -ne \
  6036.         's/^['$'\t '']['$'\t '']*\([^'$'\t '']*\).*$/\1/p'
  6037. }
  6038.  
  6039. _dict()
  6040. {
  6041.     local cur prev host port db dictfile
  6042.  
  6043.     COMPREPLY=()
  6044.     cur=${COMP_WORDS[COMP_CWORD]}
  6045.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6046.     dictfile=/usr/share/dict/words
  6047.  
  6048.     for (( i=1; i < COMP_CWORD; i++ )); do
  6049.         case "${COMP_WORDS[i]}" in
  6050.         -@(h|--host))
  6051.             host=${COMP_WORDS[i+1]}
  6052.             [ -n "$host" ] && host="-h $host"
  6053.             i=$((++i))
  6054.             ;;
  6055.         -@(p|-port))
  6056.             port=${COMP_WORDS[i+1]}
  6057.             [ -n "$port" ] && port="-p $port"
  6058.             i=$((++i))
  6059.             ;;
  6060.         -@(d|-database))
  6061.             db=${COMP_WORDS[i+1]}
  6062.             [ -n "$db" ] && host="-d $db"
  6063.             i=$((++i))
  6064.             ;;
  6065.         *)
  6066.             ;;
  6067.         esac
  6068.     done
  6069.  
  6070.     if [[ "$cur" = -* ]]; then
  6071.         COMPREPLY=( $( compgen -W '-h --host -p --port -d --database \
  6072.                    -m --match -s --strategy -c --config -C \
  6073.                    --nocorrect -D --dbs -S --strats -H \
  6074.                    --serverhelp -i --info -I --serverinfo \
  6075.                    -a --noauth -u --user -k --key -V --version \
  6076.                    -L --license --help -v --verbose -r --raw \
  6077.                    -P --pager --debug --html --pipesize --client' \
  6078.                    -- "$cur" ) )
  6079.         return 0
  6080.     fi
  6081.  
  6082.     case "$prev" in
  6083.     -@(d|-database|i|info))
  6084.         COMPREPLY=( $( compgen -W '$( _dictdata -D )' -- "$cur" ) )
  6085.         return 0
  6086.         ;;
  6087.     -@(s|-strategy))
  6088.         COMPREPLY=( $( compgen -W '$( _dictdata -S )' -- "$cur" ) )
  6089.         return 0
  6090.         ;;
  6091.     *)
  6092.         ;;
  6093.     esac
  6094.  
  6095.     [ -r $dictfile ] && \
  6096.         COMPREPLY=( $( compgen -W '$( cat $dictfile )' -- "$cur" ) )
  6097. }
  6098. complete -F _dict $default dict rdict
  6099. }
  6100.  
  6101. # cdrecord(1) completion
  6102. #
  6103. have cdrecord &&
  6104. _cdrecord()
  6105. {
  6106.     local cur prev i generic_options track_options track_mode
  6107.  
  6108.     COMPREPLY=()
  6109.     cur=${COMP_WORDS[COMP_CWORD]}
  6110.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6111.  
  6112.     # foo=bar style option
  6113.     if [[ "$cur" == *=* ]]; then
  6114.         prev=${cur/=*/}
  6115.         cur=${cur/*=/}
  6116.         case "$prev" in
  6117.             @(text|cue)file)
  6118.                 _filedir
  6119.                 return 0
  6120.                 ;;
  6121.             blank)
  6122.                 COMPREPLY=( $( compgen -W 'help all fast \
  6123.                 track unreserve trtail unclose session' \
  6124.                 -- $cur ) )
  6125.                 return 0
  6126.                 ;;
  6127.             driveropts)
  6128.                 COMPREPLY=( $( compgen -W 'burnfree noburnfree\
  6129.                   varirec= audiomaster forcespeed noforcespeed\
  6130.                   speedread nospeedread singlesession \
  6131.                   nosinglesession hidecdr nohidecdr tattooinfo\
  6132.                   tattoofile=' -- $cur ) )
  6133.                 return 0
  6134.                 ;;
  6135.         esac
  6136.     fi
  6137.  
  6138.     generic_options=(-version -v -V -d -silent -s -force -immed -dummy \
  6139.              -dao -raw -raw96r -raw96p -raw16 -multi -msinfo -toc \
  6140.              -atip -fix -nofix -waiti -load -lock -eject -format \
  6141.              -setdropts -checkdrive -prcap -inq -scanbus -reset \
  6142.              -abort -overburn -ignsize -useinfo -packet -noclose \
  6143.              -text debug= kdebug= kd= minbuf= speed= blank= fs= \
  6144.              dev= gracetime= timeout= driver= driveropts= \
  6145.              defpregap= pktsize= mcn= textfile= cuefile=)
  6146.     track_options=(-audio -swab -data -mode2 -xa -xa1 -xa2 -xamix -cdi \
  6147.                -isosize -pad padsize= -nopad -shorttrack -noshorttrack\
  6148.                pregap= -preemp -nopreemp -copy -nocopy -scms tcsize= \
  6149.                isrc= index=)
  6150.     # look if previous was either a file or a track option
  6151.     track_mode=0
  6152.     if [ $COMP_CWORD -gt 1 ]; then
  6153.         if [ -f "$prev" ]; then
  6154.             track_mode=1
  6155.         else
  6156.             for (( i=0; i < ${#track_options[@]}; i++ )); do
  6157.                 if [[ "${track_options[i]}" == "$prev" ]]; then
  6158.                     track_mode=1
  6159.                     break
  6160.                 fi
  6161.             done
  6162.         fi
  6163.     fi
  6164.  
  6165.     # files are always eligible completion
  6166.     _filedir
  6167.     # track options are always available
  6168.     COMPREPLY=( ${COMPREPLY[@]} $( compgen -W '${track_options[@]}' -- $cur ) )
  6169.     # general options are no more available after file or track option
  6170.     if [ $track_mode -eq 0 ]; then
  6171.         COMPREPLY=( ${COMPREPLY[@]} \
  6172.                 $( compgen -W '${generic_options[@]}' -- $cur ) )
  6173.     fi
  6174.  
  6175. } &&
  6176. complete -F _cdrecord $filenames cdrecord
  6177.  
  6178. # mkisofs(8) completion
  6179. #
  6180. have mkisofs &&
  6181. _mkisofs()
  6182. {
  6183.     local cur prev
  6184.  
  6185.     COMPREPLY=()
  6186.     cur=${COMP_WORDS[COMP_CWORD]}
  6187.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6188.  
  6189.     case "$prev" in
  6190.         -@(o|abstract|biblio|check-session|copyright|log-file|root-info|prep-boot|*-list))
  6191.             _filedir
  6192.             return 0
  6193.             ;;
  6194.         -*-charset)
  6195.             COMPREPLY=( $( mkisofs -input-charset help 2>&1 | \
  6196.                     tail +3 | grep "^$cur") )
  6197.             return 0
  6198.             ;;
  6199.         -uid)
  6200.             _uids
  6201.             return 0
  6202.             ;;
  6203.         -gid)
  6204.             _gids
  6205.             return 0
  6206.             ;;
  6207.     esac
  6208.  
  6209.     if [[ "$cur" == -* ]]; then
  6210.         COMPREPLY=( $( compgen -W '-abstract -A -allow-lowercase \
  6211.                 -allow-multidot -biblio -cache-inodes \
  6212.                 -no-cache-inodes -b -eltorito-alt-boot -B -G \
  6213.                 -hard-disk-boot -no-emul-boot -no-boot \
  6214.                 -boot-load-seg -boot-load-size \
  6215.                 -boot-info-table -C -c -check-oldname \
  6216.                 -check-session -copyright -d -D -dir-mode \
  6217.                 -dvd-video -f -file-mode -gid -gui \
  6218.                 -graft-points -hide -hide-list -hidden \
  6219.                 -hidden-list -hide-joliet -hide-joliet-list \
  6220.                 -hide-joliet-trans-tbl -hide-rr-moved \
  6221.                 -input-charset -output-charset -iso-level -J \
  6222.                 -joliet-long -jcharset -l -L -log-file -m \
  6223.                 -exclude-list -max-iso9660-filenames -M -N \
  6224.                 -new-dir-mode -nobak -no-bak -force-rr -no-rr \
  6225.                 -no-split-symlink-components \
  6226.                 -no-split-symlink-fields -o -pad -no-pad \
  6227.                 -path-list -P -p -print-size -quiet -R -r \
  6228.                 -relaxed-filenames -sort -split-output \
  6229.                 -stream-media-size -stream-file-name -sysid -T\
  6230.                 -table-name -ucs-level -udf -uid \
  6231.                 -use-fileversion -U -no-iso-translate -V \
  6232.                 -volset -volset-size -volset-seqno -v -x -z \
  6233.                 -hfs -apple -map -magic -hfs-creator \
  6234.                 -hfs-type -probe -no-desktop -mac-name \
  6235.                 -boot-hfs-file -part -auto -cluster-size \
  6236.                 -hide-hfs -hide-hfs-list -hfs-volid \
  6237.                 -icon-position -root-info -prep-boot \
  6238.                 -input-hfs-charset -output-hfs-charset \
  6239.                 -hfs-unlock -hfs-bless -hfs-parms --cap \
  6240.                 --netatalk --double --ethershare --ushare \
  6241.                 --exchange --sgi --xinet --macbin --single \
  6242.                 --dave --sfm --osx-double --osx-hfs' -- $cur ))
  6243.     else
  6244.         _filedir
  6245.     fi
  6246.  
  6247. } &&
  6248. complete -F _mkisofs $filenames mkisofs
  6249.  
  6250. # mc(1) completion
  6251. #
  6252. have mc &&
  6253. _mc()
  6254. {
  6255.     local cur prev
  6256.  
  6257.     COMPREPLY=()
  6258.     cur=${COMP_WORDS[COMP_CWORD]}
  6259.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6260.  
  6261.     # -name value style option
  6262.     case "$prev" in
  6263.         -@(e|v|l|P))
  6264.             _filedir
  6265.             return 0
  6266.             ;;
  6267.     esac
  6268.  
  6269.     # --name=value style option
  6270.     if [[ "$cur" == *=* ]]; then
  6271.         prev=${cur/=*/}
  6272.         cur=${cur/*=/}
  6273.         case "$prev" in
  6274.             --@(edit|view|ftplog|printwd))
  6275.                 _filedir
  6276.                 return 0
  6277.                 ;;
  6278.         esac
  6279.     fi
  6280.  
  6281.     if [[ "$cur" == -* ]]; then
  6282.         COMPREPLY=( $( compgen -W '-a --stickchars -b --nocolor -c \
  6283.             --color -C --colors= -d --nomouse -e --edit= -f \
  6284.             --datadir -k --resetsoft -l --ftplog= -P --printwd= \
  6285.             -s --slow -t --termcap -u --nosubshell -U --subshell \
  6286.             -v --view= -V --version -x --xterm -h --help' -- $cur ) )
  6287.     else
  6288.         _filedir -d
  6289.     fi
  6290. } &&
  6291. complete -F _mc $filenames mc
  6292.  
  6293. # yum(8) completion
  6294. #
  6295. have yum && {
  6296. _yum()
  6297. {
  6298.     local cur prev special
  6299.     
  6300.     COMPREPLY=()
  6301.     cur=${COMP_WORDS[COMP_CWORD]}
  6302.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6303.  
  6304.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  6305.         if [[ ${COMP_WORDS[i]} == @(install|update|upgrade|remove|erase|deplist) ]]; then
  6306.             special=${COMP_WORDS[i]}
  6307.         fi
  6308.     done
  6309.  
  6310.     if [ -n "$special" ]; then
  6311.         case $special in
  6312.         install|deplist)
  6313.             COMPREPLY=( $( compgen -W '$( yum -C list | cut -d" " -f1 )' -- $cur ) )
  6314.             return 0
  6315.             ;;
  6316.         *)
  6317.             _rpm_installed_packages
  6318.             return 0
  6319.             ;;
  6320.         esac
  6321.     fi
  6322.  
  6323.     case $cur in
  6324.         --*)
  6325.         COMPREPLY=( $( compgen -W '--installroot --version --help --enablerepo --disablerepo --exclude --obsoletes --noplugins' -- $cur ) )
  6326.         return 0
  6327.         ;;
  6328.         -*)
  6329.         COMPREPLY=( $( compgen -W '-c -e -d -y -t -R -C -h' -- $cur ) )
  6330.         return 0
  6331.         ;;
  6332.     esac
  6333.  
  6334.     case $prev in
  6335.         list)
  6336.         COMPREPLY=( $( compgen -W 'all available updates installed extras obsoletes recent' -- $cur ) )
  6337.         ;;
  6338.         clean)
  6339.         COMPREPLY=( $( compgen -W 'packages headers metadata cache dbcache all' -- $cur ) )
  6340.         ;;
  6341.         localinstall)
  6342.         _filedir rpm
  6343.         ;;
  6344.         -c)
  6345.         _filedir
  6346.         ;;
  6347.         --installroot)
  6348.         _filedir -d
  6349.         ;;
  6350.         *)
  6351.         COMPREPLY=( $( compgen -W 'install update check-update upgrade remove list \
  6352.                         search info provides clean groupinstall groupupdate \
  6353.                         grouplist deplist erase groupinfo groupremove \
  6354.                         localinstall localupdate makecache resolvedep \
  6355.                         shell whatprovides' -- $cur ) )
  6356.         ;;
  6357.     esac
  6358. }
  6359. complete -F _yum $filenames yum
  6360.  
  6361. # yum-arch(8) completion
  6362. #
  6363. _yum_arch()
  6364. {
  6365.     local cur
  6366.     COMPREPLY=()
  6367.     cur=${COMP_WORDS[COMP_CWORD]}
  6368.  
  6369.     case "$cur" in
  6370.     -*)
  6371.         COMPREPLY=( $( compgen -W '-d -v -vv -n -c -z -s -l -q' -- $cur ) )
  6372.         ;;
  6373.     *)
  6374.         _filedir -d
  6375.         ;;
  6376.     esac
  6377.  
  6378.     return 0
  6379.  
  6380. }
  6381. complete -F _yum_arch $filenames yum-arch
  6382. }
  6383.  
  6384. # ImageMagick completion
  6385. #
  6386. have convert && {
  6387. _ImageMagick()
  6388. {
  6389.     local prev
  6390.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6391.  
  6392.     case "$prev" in
  6393.         -channel)
  6394.             COMPREPLY=( $( compgen -W 'Red Green Blue Opacity \
  6395.                 Matte Cyan Magenta Yellow Black' -- $cur ) )
  6396.             return 0
  6397.             ;;
  6398.         -colormap)
  6399.             COMPREPLY=( $( compgen -W 'shared private' -- $cur ) )
  6400.             return 0
  6401.             ;;
  6402.         -colorspace)
  6403.             COMPREPLY=( $( compgen -W 'GRAY OHTA RGB Transparent \
  6404.                 XYZ YCbCr YIQ YPbPr YUV CMYK' -- $cur ) )
  6405.             return 0
  6406.             ;;
  6407.         -compose)
  6408.             COMPREPLY=( $( compgen -W 'Over In Out Atop Xor Plus \
  6409.                 Minus Add Subtract Difference Multiply Bumpmap\
  6410.                 Copy CopyRed CopyGreen CopyBlue CopyOpacity' \
  6411.                 -- $cur ) )
  6412.             return 0
  6413.             ;;
  6414.         -compress)
  6415.             COMPREPLY=( $( compgen -W 'None BZip Fax Group4 JPEG \
  6416.                 Lossless LZW RLE Zip' -- $cur ) )
  6417.             return 0
  6418.             ;;
  6419.         -dispose)
  6420.             COMPREPLY=( $( compgen -W 'Undefined None Background \
  6421.                             Previous' -- $cur ) )
  6422.             return 0
  6423.             ;;
  6424.         -encoding)
  6425.             COMPREPLY=( $( compgen -W 'AdobeCustom AdobeExpert \
  6426.                 AdobeStandard AppleRoman BIG5 GB2312 Latin2 \
  6427.                 None SJIScode Symbol Unicode Wansung' -- $cur))
  6428.             return 0
  6429.             ;;
  6430.         -endian)
  6431.             COMPREPLY=( $( compgen -W 'MSB LSB' -- $cur ) )
  6432.             return 0
  6433.             ;;
  6434.         -filter)
  6435.             COMPREPLY=( $( compgen -W 'Point Box Triangle Hermite \
  6436.                 Hanning Hamming Blackman Gaussian Quadratic \
  6437.                 Cubic Catrom Mitchell Lanczos Bessel Sinc' \
  6438.                 -- $cur ) )
  6439.             return 0
  6440.             ;;
  6441.         -format)
  6442.             COMPREPLY=( $( convert -list format | \
  6443.                     awk '/ [r-][w-][+-] / {print $1}' | \
  6444.                     tr -d '*' | tr [:upper:] [:lower:] | \
  6445.                     grep "^$cur" ) )
  6446.             return 0
  6447.             ;;
  6448.         -gravity)
  6449.             COMPREPLY=( $( compgen -W 'Northwest North NorthEast \
  6450.                 West Center East SouthWest South SouthEast' \
  6451.                 -- $cur ) )
  6452.             return 0
  6453.             ;;
  6454.         -intent)
  6455.             COMPREPLY=( $( compgen -W 'Absolute Perceptual \
  6456.                     Relative Saturation' -- $cur ) )
  6457.             return 0
  6458.             ;;
  6459.         -interlace)
  6460.             COMPREPLY=( $( compgen -W 'None Line Plane Partition' \
  6461.                     -- $cur ) )
  6462.             return 0
  6463.             ;;
  6464.         -limit)
  6465.             COMPREPLY=( $( compgen -W 'Disk File Map Memory' \
  6466.                     -- $cur ) )
  6467.             return 0
  6468.             ;;
  6469.         -list)
  6470.             COMPREPLY=( $( compgen -W 'Delegate Format Magic \
  6471.                     Module Resource Type' -- $cur ) )
  6472.             return 0
  6473.             ;;
  6474.         -map)
  6475.             COMPREPLY=( $( compgen -W 'best default gray red \
  6476.                     green blue' -- $cur ) )
  6477.             _filedir
  6478.             return 0
  6479.             ;;
  6480.         -noise)
  6481.             COMPREPLY=( $( compgen -W 'Uniform Gaussian \
  6482.                     Multiplicative \
  6483.                 Impulse Laplacian Poisson' -- $cur ) )
  6484.             return 0
  6485.             ;;
  6486.         -preview)
  6487.             COMPREPLY=( $( compgen -W 'Rotate Shear Roll Hue \
  6488.                     Saturation Brightness Gamma Spiff \
  6489.                     Dull Grayscale Quantize Despeckle \
  6490.                     ReduceNoise AddNoise Sharpen Blur \
  6491.                     Treshold EdgeDetect Spread Shade \
  6492.                     Raise Segment Solarize Swirl Implode \
  6493.                     Wave OilPaint CharcoalDrawing JPEG' \
  6494.                     -- $cur ) )
  6495.             return 0
  6496.             ;;
  6497.         -@(mask|profile|texture|tile|write))
  6498.             _filedir
  6499.             return 0
  6500.             ;;
  6501.         -type)
  6502.             COMPREPLY=( $( compgen -W 'Bilevel Grayscale Palette \
  6503.                     PaletteMatte TrueColor TrueColorMatte \
  6504.                     ColorSeparation ColorSeparationlMatte \
  6505.                     Optimize' -- $cur ) )
  6506.             return 0
  6507.             ;;
  6508.         -units)
  6509.             COMPREPLY=( $( compgen -W 'Undefined PixelsPerInch \
  6510.                     PixelsPerCentimeter' -- $cur ) )
  6511.             return 0
  6512.             ;;
  6513.         -virtual-pixel)
  6514.             COMPREPLY=( $( compgen -W 'Constant Edge mirror tile' \
  6515.                     -- $cur ) )
  6516.             return 0
  6517.             ;;
  6518.         -visual)
  6519.             COMPREPLY=( $( compgen -W 'StaticGray GrayScale \
  6520.                     StaticColor PseudoColor TrueColor \
  6521.                     DirectColor defaut visualid' -- $cur ))
  6522.             return 0
  6523.             ;;
  6524.     esac
  6525. }
  6526.  
  6527. _convert()
  6528. {
  6529.     local cur
  6530.  
  6531.     COMPREPLY=()
  6532.     cur=${COMP_WORDS[COMP_CWORD]}
  6533.  
  6534.     _ImageMagick
  6535.  
  6536.     if [[ "$cur" == -* ]]; then
  6537.         COMPREPLY=( $( compgen -W '-adjoin -affine -antialias -append \
  6538.             -authenticate -average -background -black-threshold \
  6539.             -blue-primary -blur -border -bordercolor -channel \
  6540.             -charcoal -chop -clip -coalesce -colorize -colors \
  6541.             -colorspace -comment -compress -contrast -convolve \
  6542.             -crop -cycle -debug -deconstruct -delay -density \
  6543.             -depth -despeckle -display -dispose -dither -draw \
  6544.             -edge -emboss -encoding -endian -enhance -equalize \
  6545.             -extract -fill -filter -flatten -flip -flop -font \
  6546.             -frame -fuzz -gamma -gaussian -geometry \
  6547.             -green-primary -gravity -help -implode -intent \
  6548.             -interlace -label -lat -level -limit -list -log -loop \
  6549.             -map -mask -matte -median -modulate -monochrome \
  6550.             -morph -mosaic -negate -noop -noise -normalize \
  6551.             -opaque -ordered-dither -page -paint -ping -pointsize \
  6552.             -preview -profile -quality -raise -random-threshold \
  6553.             -region -raise -red-primary -render -resize -resample \
  6554.             -roll -rotate -sample -sampling-factor -scale -scene \
  6555.             -seed -segment -shade -sharpen -shave -shear -size \
  6556.             -solarize -spread -stroke -strokewidth -swirl \
  6557.             -texture -threshold -thumbnail -tile -transform \
  6558.             -transparent -treedepth -trim -type -undercolor \
  6559.             -units -unsharp -verbose -version -view \
  6560.             -virtual-pixel -wave -white-point -white-threshold \
  6561.             -write' -- $cur ) )
  6562.     elif [[ "$cur" == +* ]]; then
  6563.         COMPREPLY=( $( compgen -W '+adjoin +append +compress \
  6564.             +contrast +debug +dither +endian +gamma +label +map \
  6565.             +mask +matte +negate +noise +page +raise +render \
  6566.             +write' -- $cur ) ) 
  6567.     else
  6568.         _filedir
  6569.     fi
  6570. }
  6571. complete -F _convert $filenames convert
  6572.  
  6573. _mogrify()
  6574. {
  6575.     local cur
  6576.  
  6577.     COMPREPLY=()
  6578.     cur=${COMP_WORDS[COMP_CWORD]}
  6579.  
  6580.     _ImageMagick
  6581.  
  6582.     if [[ "$cur" == -* ]]; then
  6583.         COMPREPLY=( $( compgen -W '-affine -antialias -authenticate \
  6584.             -background -black-threshold -blue-primary -blur \
  6585.             -border -bordercolor -channel -charcoal -chop \
  6586.             -colorize -colors -colorspace -comment -compress \
  6587.             -contrast -convolve -crop -cycle -debug -delay \
  6588.             -density -depth -despeckle -display -dispose -dither \
  6589.             -draw -edge -emboss -encoding -endian -enhance \
  6590.             -equalize -extract -fill -filter -flip -flop -font \
  6591.             -format -frame -fuzz -gamma -gaussian -geometry \
  6592.             -green-primary -implode -interlace -help -label -lat \
  6593.             -level -limit -list -log -loop -map -mask -matte \
  6594.             -median -modulate -monochrome -negate -noop \
  6595.             -normalize -opaque -page -paint -fill -ordered-dither \
  6596.             -pointsize -profile -quality -raise -random-threshold \
  6597.             -red-primary -region -resample -resize -roll -rotate \
  6598.             -sample -sampling-factor -scale -scene -seed -segment \
  6599.             -shade -sharpen -shear -size -solarize -spread \
  6600.             -stroke -strokewidth -swirl -texture -threshold \
  6601.             -thumbnail -tile -transform -transparent -treedepth \
  6602.             -trim -type -undercolor -units -unsharp -verbose \
  6603.             -version -view -virtual-pixel -wave -white-point \
  6604.             -white-threshold' -- $cur ) )
  6605.     elif [[ "$cur" == +* ]]; then
  6606.         COMPREPLY=( $( compgen -W '+compress +contrast +debug +dither \
  6607.             +endian +gamma +label +map +mask +matte +negate +page \
  6608.             +raise' -- $cur ) ) 
  6609.     else
  6610.         _filedir
  6611.     fi
  6612. }
  6613. complete -F _mogrify $filenames mogrify
  6614.  
  6615. _display()
  6616. {
  6617.     local cur
  6618.  
  6619.     COMPREPLY=()
  6620.     cur=${COMP_WORDS[COMP_CWORD]}
  6621.  
  6622.     _ImageMagick
  6623.  
  6624.     if [[ "$cur" == -* ]]; then
  6625.         COMPREPLY=( $( compgen -W '-authenticate -backdrop -border \
  6626.             -colormap -colors -colorspace -comment -compress \
  6627.             -contrast -crop -debug -delay -density -depth \
  6628.             -despeckle -display -dispose -dither -edge -endian \
  6629.             -enhance -extract -filter -flip -flop -frame -gamma \
  6630.             -geometry -help -immutable -interlace -label -limit \
  6631.             -log -map -matte -monochrome -negate -noop -page \
  6632.             -quality -raise -remote -roll -rotate -sample \
  6633.             -sampling-factor -scene -segment -sharpen -size \
  6634.             -texture -treedepth -trim -update -verbose -version \
  6635.             -virtual-pixel -window -window_group -write' -- $cur))
  6636.     elif [[ "$cur" == +* ]]; then
  6637.         COMPREPLY=( $( compgen -W '+compress +contrast +debug +dither \
  6638.             +endian +gamma +label +map +matte +negate +page \
  6639.             +raise +write' -- $cur ) ) 
  6640.     else
  6641.         _filedir
  6642.     fi
  6643. }
  6644. complete -F _display $filenames display
  6645.  
  6646. _animate()
  6647. {
  6648.     local cur
  6649.  
  6650.     COMPREPLY=()
  6651.     cur=${COMP_WORDS[COMP_CWORD]}
  6652.  
  6653.     _ImageMagick
  6654.  
  6655.     if [[ "$cur" == -* ]]; then
  6656.         COMPREPLY=( $( compgen -W '-authenticate -backdrop -colormap \
  6657.             -colors -colorspace -crop -debug -delay -density \
  6658.             -depth -display -dither -extract -gamma -geometry \
  6659.             -help -interlace -limit -log -matte -map -monochrome \
  6660.             -noop -pause -remote -rotate -sampling-factor -scene \
  6661.             -size -treedepth -trim -verbose -version -visual \
  6662.             -virtual-pixel -window' -- $cur ) )
  6663.     elif [[ "$cur" == +* ]]; then
  6664.         COMPREPLY=( $( compgen -W '+debug +dither +gamma +map +matte' -- $cur ) ) 
  6665.     else
  6666.         _filedir
  6667.     fi
  6668. }
  6669. complete -F _animate $filenames animate
  6670.  
  6671. _identify()
  6672. {
  6673.     local cur
  6674.  
  6675.     COMPREPLY=()
  6676.     cur=${COMP_WORDS[COMP_CWORD]}
  6677.  
  6678.     _ImageMagick
  6679.  
  6680.     if [[ "$cur" == -* ]]; then
  6681.         COMPREPLY=( $( compgen -W '-authenticate -debug -density \
  6682.             -depth -extract -format -help -interlace -limit -list \
  6683.             -log -size -sampling-factor -verbose -version \
  6684.             -virtual-pixel' -- $cur ) )
  6685.     elif [[ "$cur" == +* ]]; then
  6686.         COMPREPLY=( $( compgen -W '+debug ' -- $cur ) ) 
  6687.     else
  6688.         _filedir
  6689.     fi
  6690. }
  6691. complete -F _identify $filenames identify
  6692.  
  6693. _montage()
  6694. {
  6695.     local cur
  6696.  
  6697.     COMPREPLY=()
  6698.     cur=${COMP_WORDS[COMP_CWORD]}
  6699.  
  6700.     _ImageMagick
  6701.  
  6702.     if [[ "$cur" == -* ]]; then
  6703.         COMPREPLY=( $( compgen -W '-adjoin -affine -authenticate \
  6704.             -blue-primary -blur -colors -colorspace -comment \
  6705.             -compose -compress -crop -debug -density -depth \
  6706.             -display -dispose -dither -draw -encoding -endian \
  6707.             -extract -fill -filter -flip -flop -frame -gamma \
  6708.             -geometry -gravity -green-primary -interlace -help \
  6709.             -label -limit -log -matte -mode -monochrome -noop \
  6710.             -page -pointsize -quality -red-primary -resize \
  6711.             -rotate -sampling-factor -scene -shadow -size \
  6712.             -stroke -texture -thumbnail -tile -transform \
  6713.             -transparent -treedepth -trim -type -verbose \
  6714.             -version -virtual-pixel -white-point' -- $cur ) )
  6715.     elif [[ "$cur" == +* ]]; then
  6716.         COMPREPLY=( $( compgen -W '+adjoin +compress +debug +dither \
  6717.             +endian +gamma +label +matte +page' -- $cur ) ) 
  6718.     else
  6719.         _filedir
  6720.     fi
  6721. }
  6722. complete -F _montage $filenames montage
  6723.  
  6724. _composite()
  6725. {
  6726.     local cur
  6727.  
  6728.     COMPREPLY=()
  6729.     cur=${COMP_WORDS[COMP_CWORD]}
  6730.  
  6731.     _ImageMagick
  6732.  
  6733.     if [[ "$cur" == -* ]]; then
  6734.         COMPREPLY=( $( compgen -W '-affine -authenticate \
  6735.             -blue-primary -colors -colorspace -comment -compose \
  6736.             -compress -debug -density -depth -displace -display \
  6737.             -dispose -dissolve -dither -encoding -endian -extract \
  6738.             -filter -font -geometry -gravity -green-primary -help \
  6739.             -interlace -label -limit -log -matte -monochrome \
  6740.             -negate -page -profile -quality -red-primary -rotate \
  6741.             -resize -sampling-factor -scene -sharpen -size \
  6742.             -stegano -stereo -thumbnail -tile -transform \
  6743.             -treedepth -type -units -unsharp -verbose -version \
  6744.             -virtual-pixel -watermark -white-point -write' \
  6745.             -- $cur ) )
  6746.     elif [[ "$cur" == +* ]]; then
  6747.         COMPREPLY=( $( compgen -W '+compress +debug +dither +endian +label \
  6748.             +matte +negate +page +write' -- $cur ) ) 
  6749.     else
  6750.         _filedir
  6751.     fi
  6752. }
  6753. complete -F _composite $filenames composite
  6754. }
  6755.  
  6756. # dd(1) completion
  6757. #
  6758. have dd &&
  6759. _dd()
  6760. {
  6761.      local cur
  6762.  
  6763.      COMPREPLY=()
  6764.      cur=${COMP_WORDS[COMP_CWORD]}
  6765.  
  6766.      case "$cur" in
  6767.      if=*|of=*)
  6768.          cur=${cur#*=}
  6769.          _filedir
  6770.          return 0
  6771.          ;;
  6772.      conv=*)
  6773.          cur=${cur#*=}
  6774.          COMPREPLY=( $( compgen -W 'ascii ebcdic ibm block unblock \
  6775.                 lcase notrunc ucase swab noerror sync' \
  6776.                 -- $cur ) )
  6777.          return 0
  6778.          ;;
  6779.      esac
  6780.  
  6781.      _expand || return 0
  6782.  
  6783.      COMPREPLY=( $( compgen -W '--help --version' -- $cur ) \
  6784.              $( compgen -W 'bs cbs conv count ibs if obs of seek skip'\
  6785.                 -S '=' -- $cur ) )
  6786. } &&
  6787. complete -F _dd $nospace $filenames dd
  6788.  
  6789. # CUPS cancel(1) completion
  6790. #
  6791. have cancel &&
  6792. _cancel()
  6793. {
  6794.     local cur
  6795.  
  6796.     COMPREPLY=()
  6797.     cur=${COMP_WORDS[COMP_CWORD]}
  6798.  
  6799.     COMPREPLY=( $( lpstat | cut -d' ' -f1 | grep "^$cur" ) )
  6800. } &&
  6801. complete -F _cancel $filenames cancel
  6802.  
  6803. # aspell(1) completion
  6804. #
  6805. have aspell && {
  6806. _aspell_dictionary()
  6807. {
  6808.     local datadir
  6809.     datadir=/usr/lib/aspell
  6810.     COMPREPLY=( $( command ls $datadir/*.@(multi|alias) ) )
  6811.     COMPREPLY=( ${COMPREPLY[@]%.@(multi|alias)} )
  6812.     COMPREPLY=( $( compgen -W '${COMPREPLY[@]#$datadir/}' -- $cur ) )
  6813. }
  6814.  
  6815. _aspell()
  6816. {
  6817.     local cur prev
  6818.  
  6819.     COMPREPLY=()
  6820.     cur=${COMP_WORDS[COMP_CWORD]}
  6821.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6822.  
  6823.     # --name value style option
  6824.     case "$prev" in
  6825.         @(-c|-p|check))
  6826.             _filedir
  6827.             return 0
  6828.             ;;
  6829.         @(dump|create|merge))
  6830.             COMPREPLY=( $( compgen -W 'master personal repl' -- $cur ) )
  6831.             return 0
  6832.             ;;
  6833.         -d)
  6834.             _aspell_dictionary
  6835.             return 0
  6836.             ;;
  6837.     esac
  6838.  
  6839.     # --name=value style option
  6840.     if [[ "$cur" == *=* ]]; then
  6841.         prev=${cur/=*/}
  6842.         cur=${cur/*=/}
  6843.         case "$prev" in
  6844.             --@(conf|personal|repl|per-conf))
  6845.                 _filedir
  6846.                 return 0
  6847.                 ;;
  6848.             --@(conf-dir|data-dir|dict-dir|home-dir|local-data-dir|prefix))
  6849.                 _filedir -d
  6850.                 return 0
  6851.                 ;;
  6852.             --master)
  6853.                 _aspell_dictionary
  6854.                 return 0
  6855.                 ;;
  6856.             --mode)
  6857.                 COMPREPLY=( $( compgen -W 'none url email sgml tex' -- $cur ) )
  6858.                 return 0
  6859.                 ;; 
  6860.             --sug-mode)
  6861.                 COMPREPLY=( $( compgen -W 'ultra fast normal bad-speller' -- $cur ) )
  6862.                 return 0
  6863.                 ;;
  6864.             --keymapping)
  6865.                 COMPREPLY=( $( compgen -W 'aspell ispell' -- $cur ) )
  6866.                 return 0
  6867.                 ;;
  6868.         esac
  6869.     fi
  6870.  
  6871.     if [[ "$cur" == -* ]]; then
  6872.         COMPREPLY=( $( compgen -W '--conf= --conf-dir= --data-dir= --dict-dir= \
  6873.             --encoding= --add-filter= --rem-filter= --mode= -e \
  6874.             -H -t --add-extra-dicts= --rem-extra-dicts= \
  6875.             --home-dir= -W --ignore= --ignore-accents \
  6876.             --dont-ignore-accents --ignore-case --dont-ignore-case \
  6877.             --ignore-repl --dont-ignore-repl --jargon= --keyboard= \
  6878.             --lang= --language-tag= --local-data-dir= -d --master= \
  6879.             --module= --add-module-search-order= \
  6880.             --rem-module-search-order= --per-conf= -p --personal= \
  6881.             --prefix= --repl= -C -B --run-together --dont-run-together \
  6882.             --run-together-limit= --run-together-min= --save-repl \
  6883.             --dont-save-repl --set-prefix --dont-set-prefix --size= \
  6884.             --spelling= --strip-accents --dont-strip-accents \
  6885.             --sug-mode= --add-word-list-path= --rem-word-list-path= \
  6886.             -b -x --backup -b|-x --dont-backup --reverse --dont-reverse \
  6887.             --time --dont-time --keymapping= --add-email-quote= \
  6888.             --rem-email-quote= --email-margin= --add-tex-command= \
  6889.             --rem-tex-command= --tex-check-comments \
  6890.             --dont-tex-check-comments --add-tex-extension= \
  6891.             --rem-tex-extension= --add-sgml-check= --rem-sgml-check= \
  6892.             --add-sgml-extension= --rem-sgml-extension=' -- $cur ) )
  6893.     else
  6894.         COMPREPLY=( $( compgen -W '-? help -c check -a pipe -l list \
  6895.             config config soundslike filter -v version dump \
  6896.             create merge' -- $cur ) )
  6897.     fi
  6898.  
  6899. }
  6900. complete -F _aspell $default aspell
  6901. }
  6902.  
  6903. # xmms(1) completion
  6904. #
  6905. have xmms &&
  6906. _xmms()
  6907. {
  6908.     local cur
  6909.  
  6910.     COMPREPLY=()
  6911.     cur=${COMP_WORDS[COMP_CWORD]}
  6912.  
  6913.     if [[ "$cur" == -* ]]; then
  6914.         COMPREPLY=( $( compgen -W '-h --help -r --rew -p --play \
  6915.             -u --pause -s --stop -t --play-pause -f --fwd -e \
  6916.             --enqueue -m --show-main-window -i --sm-client-id \
  6917.             -v --version' -- $cur ) )
  6918.     else
  6919.         _filedir '@(mp[23]|MP[23]|ogg|OGG|wav|WAV|pls|m3u|xm|mod|s[3t]m|it|mtm|ult|flac)'
  6920.  
  6921.     fi
  6922.  
  6923. } &&
  6924. complete -F _xmms $filenames xmms
  6925.  
  6926. # info(1) completion
  6927. #
  6928. have info &&
  6929. _info()
  6930. {
  6931.     local cur infopath UNAME
  6932.  
  6933.     COMPREPLY=()
  6934.     cur=${COMP_WORDS[COMP_CWORD]}
  6935.  
  6936.     _expand || return 0
  6937.  
  6938.     # default completion if parameter contains /
  6939.     if [[ "$cur" == */* ]]; then
  6940.         _filedir
  6941.         return 0
  6942.     fi
  6943.  
  6944.     infopath='/usr/share/info'
  6945.  
  6946.     if [ "${INFOPATH: -1:1}" == ':' ]; then
  6947.         infopath=${INFOPATH}${infopath}
  6948.     elif [ ${INFOPATH:+set} ]; then
  6949.         infopath=$INFOPATH
  6950.     fi
  6951.  
  6952.     infopath=$infopath:
  6953.     if [ -n "$cur" ]; then
  6954.         infopath="${infopath//://$cur* }"
  6955.     else
  6956.         infopath="${infopath//:// }"
  6957.     fi
  6958.  
  6959.     # redirect stderr for when path doesn't exist
  6960.     COMPREPLY=( $( eval command ls "$infopath" 2>/dev/null ) )
  6961.     # weed out directory path names and paths to info pages
  6962.     COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
  6963.     # weed out info dir file
  6964.     for (( i=0 ; i < ${#COMPREPLY[@]} ; ++i )); do
  6965.         if [ "${COMPREPLY[$i]}" == 'dir' ]; then
  6966.             unset COMPREPLY[$i];
  6967.         fi;
  6968.     done  
  6969.     # strip suffix from info pages
  6970.     COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} )
  6971.     COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) )
  6972.  
  6973.     return 0
  6974. } &&
  6975. complete -F _info $filenames info
  6976.  
  6977. # dhclient(1) completion
  6978. #
  6979. have dhclient && _dhclient()
  6980. {
  6981.     local cur prev
  6982.  
  6983.     COMPREPLY=()
  6984.     cur=${COMP_WORDS[COMP_CWORD]}
  6985.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6986.  
  6987.     case "$prev" in
  6988.         -@(cf|lf|pf|sf))
  6989.             _filedir
  6990.             return 0
  6991.             ;;
  6992.         -s)
  6993.             _known_hosts
  6994.             return 0
  6995.             ;;
  6996.     esac
  6997.  
  6998.     if [[ "$cur" == -* ]]; then
  6999.         COMPREPLY=( $( compgen -W '-p -d -q -1 -r -lf -pf \
  7000.             -cf -sf -s -g -n -nw -w' -- $cur ) )
  7001.     else
  7002.         _available_interfaces
  7003.     fi
  7004. } &&
  7005. complete -F _dhclient dhclient
  7006.  
  7007. # lvm(8) completion
  7008. #
  7009. have lvm && {
  7010. _volumegroups()
  7011. {
  7012.     COMPREPLY=( $(compgen -W "$( vgscan 2>/dev/null | \
  7013.         sed -n -e 's|.*Found.*"\(.*\)".*$|\1|p' )" -- $cur ) )
  7014. }
  7015.  
  7016. _physicalvolumes()
  7017. {
  7018.     COMPREPLY=( $(compgen -W "$( pvscan 2>/dev/null | \
  7019.         sed -n -e 's|^.*PV \(.*\) VG.*$|\1|p' )" -- $cur ) )
  7020. }
  7021.  
  7022. _logicalvolumes()
  7023. {
  7024.     COMPREPLY=( $(compgen -W "$( lvscan 2>/dev/null | \
  7025.         sed -n -e "s|^.*'\(.*\)'.*$|\1|p" )" -- $cur ) )
  7026. }
  7027.  
  7028. _units()
  7029. {
  7030.     COMPREPLY=( $( compgen -W 'h s b k m g t H K M G T' -- $cur ) )
  7031. }
  7032.  
  7033. _sizes()
  7034. {
  7035.     COMPREPLY=( $( compgen -W 'k K m M g G t T' -- $cur ) )
  7036. }
  7037.  
  7038. _args()
  7039. {
  7040.     args=0
  7041.     if [[ "${COMP_WORDS[0]}" == lvm ]]; then
  7042.         offset=2
  7043.     else
  7044.         offset=1
  7045.     fi
  7046.     for (( i=$offset; i < COMP_CWORD; i++ )); do
  7047.         if [[ "${COMP_WORDS[i]}" != -* ]]; then
  7048.             args=$(($args + 1))
  7049.         fi
  7050.     done
  7051. }
  7052.  
  7053. _lvmdiskscan()
  7054. {
  7055.     local cur
  7056.  
  7057.     COMPREPLY=()
  7058.     cur=${COMP_WORDS[COMP_CWORD]}
  7059.  
  7060.     if [[ "$cur" == -* ]]; then
  7061.         COMPREPLY=( $( compgen -W '-d --debug -h -? --help -l \
  7062.             --lvmpartition -v --verbose --version' -- $cur ) )
  7063.     fi
  7064. }
  7065. complete -F _lvmdiskscan lvmdiskscan
  7066.  
  7067. _pvscan()
  7068. {
  7069.     local cur
  7070.  
  7071.     COMPREPLY=()
  7072.     cur=${COMP_WORDS[COMP_CWORD]}
  7073.  
  7074.     if [[ "$cur" == -* ]]; then
  7075.         COMPREPLY=( $( compgen -W '-d --debug -e \
  7076.             --exported -n --novolumegroup -h -? \
  7077.             --help --ignorelockingfailure -P \
  7078.             --partial -s --short -u --uuid -v \
  7079.             --verbose --version' -- $cur ) )
  7080.     fi
  7081. }
  7082. complete -F _pvscan pvscan
  7083.  
  7084. _pvs()
  7085. {
  7086.     local cur prev
  7087.  
  7088.     COMPREPLY=()
  7089.     cur=${COMP_WORDS[COMP_CWORD]}
  7090.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7091.  
  7092.     case "$prev" in
  7093.         -@(o|O|-options|-sort))
  7094.             COMPREPLY=( $( compgen -W 'pv_fmt pv_uuid \
  7095.                 pv_size pv_free pv_used pv_name \
  7096.                 pv_attr pv_pe_count \
  7097.                 pv_pe_alloc_count' -- $cur ) )
  7098.             return 0
  7099.             ;;
  7100.         --units)
  7101.             _units
  7102.             return 0
  7103.             ;;
  7104.     esac
  7105.  
  7106.     if [[ "$cur" == -* ]]; then
  7107.         COMPREPLY=( $( compgen -W '--aligned -a --all -d --debug \
  7108.             -h -? --help --ignorelockingfailure --noheadings \
  7109.             --nosuffix -o --options -O --sort \
  7110.             --separator --unbuffered --units \
  7111.             -v --verbose --version' -- $cur ) )
  7112.     else
  7113.         _physicalvolumes
  7114.     fi
  7115. }
  7116. complete -F _pvs pvs
  7117.  
  7118. _pvdisplay()
  7119. {
  7120.     local cur prev
  7121.  
  7122.     COMPREPLY=()
  7123.     cur=${COMP_WORDS[COMP_CWORD]}
  7124.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7125.  
  7126.     case "$prev" in
  7127.         --units)
  7128.             _units
  7129.             return 0
  7130.             ;;
  7131.     esac
  7132.  
  7133.     if [[ "$cur" == -* ]]; then
  7134.         COMPREPLY=( $( compgen -W '-c --colon -C --columns --units \
  7135.             -v --verbose -d --debug -h --help --version' -- $cur ) )
  7136.     else
  7137.         _physicalvolumes
  7138.     fi
  7139. }
  7140. complete -F _pvdisplay pvdisplay
  7141.  
  7142. _pvchange()
  7143. {
  7144.     local cur prev
  7145.  
  7146.     COMPREPLY=()
  7147.     cur=${COMP_WORDS[COMP_CWORD]}
  7148.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7149.  
  7150.     case "$prev" in
  7151.         -@(A|x|-autobackup|--allocatable))
  7152.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7153.             return 0
  7154.             ;;
  7155.     esac
  7156.  
  7157.     if [[ "$cur" == -* ]]; then
  7158.         COMPREPLY=( $( compgen -W '-a --all -A --autobackup \
  7159.             -d --debug -h --help -t --test -u --uuid -x \
  7160.             --allocatable -v --verbose --addtag --deltag \
  7161.             --version' -- $cur ) )
  7162.     else
  7163.         _physicalvolumes
  7164.     fi
  7165. }
  7166. complete -F _pvchange pvchange
  7167.  
  7168. _pvcreate()
  7169. {
  7170.     local cur prev
  7171.  
  7172.     COMPREPLY=()
  7173.     cur=${COMP_WORDS[COMP_CWORD]}
  7174.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7175.  
  7176.     case "$prev" in
  7177.         --restorefile)
  7178.             _filedir
  7179.             return 0
  7180.             ;;
  7181.         -@(M|-metadatatype))
  7182.             COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
  7183.             return 0
  7184.             ;;
  7185.         --metadatacopies)
  7186.             COMPREPLY=( $( compgen -W '0 1 2' -- $cur ) )
  7187.             return 0
  7188.             ;;
  7189.         --@(metadatasize|setphysicalvolumesize))
  7190.             _sizes
  7191.             return 0
  7192.             ;;
  7193.     esac
  7194.  
  7195.     if [[ "$cur" == -* ]]; then
  7196.         COMPREPLY=( $( compgen -W '--restorefile -d --debug -f \
  7197.             --force -h -? --help --labelsector -M --metadatatype \
  7198.             --metadatacopies --metadatasize \
  7199.             --setphysicalvolumesize -t --test -u --uuid uuid -v \
  7200.             --verbose -y --yes --version' -- $cur ) )
  7201.     else
  7202.         _physicalvolumes
  7203.     fi
  7204. }
  7205. complete -F _pvcreate pvcreate
  7206.  
  7207. _pvmove()
  7208. {
  7209.     local cur prev
  7210.  
  7211.     COMPREPLY=()
  7212.     cur=${COMP_WORDS[COMP_CWORD]}
  7213.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7214.  
  7215.     case "$prev" in
  7216.         -@(A|-autobackup))
  7217.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7218.             return 0
  7219.             ;;
  7220.         -@(n|-name))
  7221.             _logicalvolumes
  7222.             return 0
  7223.     esac
  7224.  
  7225.     if [[ "$cur" == -* ]]; then
  7226.         COMPREPLY=( $( compgen -W '--abort -A --autobackup \
  7227.             -b --background -d --debug -f --force -h -? \
  7228.             --help -i --interval -t --test -v --verbose \
  7229.             --version -n --name' -- $cur ) )
  7230.     else
  7231.         _physicalvolumes
  7232.     fi
  7233. }
  7234. complete -F _pvmove pvmove
  7235.  
  7236. _pvremove()
  7237. {
  7238.     local cur
  7239.  
  7240.     COMPREPLY=()
  7241.     cur=${COMP_WORDS[COMP_CWORD]}
  7242.  
  7243.     if [[ "$cur" == -* ]]; then
  7244.         COMPREPLY=( $( compgen -W '-d --debug -f --force -h -? \
  7245.             --help -y --yes -t --test -v --verbose \
  7246.             --version' -- $cur ) )
  7247.     else
  7248.         _physicalvolumes
  7249.     fi
  7250. }
  7251. complete -F _pvremove pvremove
  7252.  
  7253. _vgscan()
  7254. {
  7255.     local cur
  7256.  
  7257.     COMPREPLY=()
  7258.     cur=${COMP_WORDS[COMP_CWORD]}
  7259.  
  7260.     if [[ "$cur" == -* ]]; then
  7261.         COMPREPLY=( $( compgen -W '-d --debug -h --help \
  7262.             --ignorelockingfailure --mknodes -P \
  7263.             --partial -v --verbose --version' -- $cur ) )
  7264.     fi
  7265. }
  7266. complete -F _vgscan vgscan
  7267.  
  7268. _vgs()
  7269. {
  7270.     local cur prev
  7271.  
  7272.     COMPREPLY=()
  7273.     cur=${COMP_WORDS[COMP_CWORD]}
  7274.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7275.  
  7276.     case "$prev" in
  7277.         -@(o|O|-options|-sort))
  7278.             COMPREPLY=( $( compgen -W 'vg_fmt vg_uuid vg_name \
  7279.                 vg_attr vg_size vg_free vg_sysid \
  7280.                 vg_extent_size vg_extent_count vg_free_count \
  7281.                 max_lv max_pv pv_count lv_count snap_count \
  7282.                 vg_seqno' -- $cur ) )
  7283.             return 0
  7284.             ;;
  7285.         --units)
  7286.             _units
  7287.             return 0
  7288.             ;;
  7289.     esac
  7290.  
  7291.     if [[ "$cur" == -* ]]; then
  7292.         COMPREPLY=( $( compgen -W '--aligned -d --debug \
  7293.             -h --help --ignorelockingfailure --noheadings \
  7294.             --nosuffix -o --options -O --sort -P --partial \
  7295.             --separator --unbuffered --units \
  7296.             -v --verbose --version' -- $cur ) )
  7297.     else
  7298.         _volumegroups
  7299.     fi
  7300. }
  7301. complete -F _vgs vgs
  7302.  
  7303. _vgdisplay()
  7304. {
  7305.     local cur prev
  7306.  
  7307.     COMPREPLY=()
  7308.     cur=${COMP_WORDS[COMP_CWORD]}
  7309.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7310.  
  7311.     case "$prev" in
  7312.         --units)
  7313.             _units
  7314.             return 0
  7315.             ;;
  7316.     esac
  7317.  
  7318.     if [[ "$cur" == -* ]]; then
  7319.         COMPREPLY=( $( compgen -W '-c --colon -C --columns --units \
  7320.             -P --partial -A --activevolumegroups -v --verbose \
  7321.             -d --debug -h --help --version' -- $cur ) )
  7322.     else
  7323.         _volumegroups
  7324.     fi
  7325. }
  7326. complete -F _vgdisplay vgdisplay
  7327.  
  7328. _vgchange()
  7329. {
  7330.     local cur prev
  7331.  
  7332.     COMPREPLY=()
  7333.     cur=${COMP_WORDS[COMP_CWORD]}
  7334.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7335.  
  7336.     case "$prev" in
  7337.         -@(a|A|x|-available|-autobackup|-resizeable))
  7338.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7339.             return 0
  7340.             ;;
  7341.     esac
  7342.  
  7343.     if [[ "$cur" == -* ]]; then
  7344.         COMPREPLY=( $( compgen -W '-A --autobackup --alloc -P \
  7345.             --partial -d --debug -h --help --ignorelockingfailure \
  7346.             -t --test -u --uuid -v --verbose --version -a \
  7347.             --available -x --resizeable -l --logicalvolume \
  7348.             --addtag --deltag' -- $cur ) )
  7349.     else
  7350.         _volumegroups
  7351.     fi
  7352. }
  7353. complete -F _vgchange vgchange
  7354.  
  7355. _vgcreate()
  7356. {
  7357.     local cur prev
  7358.  
  7359.     COMPREPLY=()
  7360.     cur=${COMP_WORDS[COMP_CWORD]}
  7361.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7362.  
  7363.     case "$prev" in
  7364.         -@(A|-autobackup))
  7365.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7366.             return 0
  7367.             ;;
  7368.         -@(M|-metadatatype))
  7369.             COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
  7370.             return 0
  7371.             ;;
  7372.         -@(s|-physicalextentsize))
  7373.             _sizes
  7374.             return 0
  7375.             ;;
  7376.     esac
  7377.  
  7378.     if [[ "$cur" == -* ]]; then
  7379.         COMPREPLY=( $( compgen -W '-A --autobackup --addtag \
  7380.             --alloc -d --debug -h --help -l --maxlogicalvolumes \
  7381.             -M --metadatatype -p --maxphysicalvolumes -s \
  7382.             --physicalextentsize -t --test -v --verbose \
  7383.             --version' -- $cur ) )
  7384.     else
  7385.         _args
  7386.         if [ $args -eq 0 ]; then
  7387.             _volumegroups
  7388.         else
  7389.             _physicalvolumes
  7390.         fi
  7391.     fi
  7392. }
  7393. complete -F _vgcreate vgcreate
  7394.  
  7395. _vgremove()
  7396. {
  7397.     local cur
  7398.  
  7399.     COMPREPLY=()
  7400.     cur=${COMP_WORDS[COMP_CWORD]}
  7401.  
  7402.     if [[ "$cur" == -* ]]; then
  7403.         COMPREPLY=( $( compgen -W '-d --debug -h --help -t --test \
  7404.         -v --verbose --version' -- $cur ) )
  7405.     else
  7406.         _volumegroups
  7407.     fi
  7408. }
  7409. complete -F _vgremove vgremove
  7410.  
  7411. _vgrename()
  7412. {
  7413.     local cur prev
  7414.  
  7415.     COMPREPLY=()
  7416.     cur=${COMP_WORDS[COMP_CWORD]}
  7417.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7418.  
  7419.     case "$prev" in
  7420.         -@(A|-autobackup))
  7421.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7422.             return 0
  7423.             ;;
  7424.     esac
  7425.  
  7426.     if [[ "$cur" == -* ]]; then
  7427.         COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -h \
  7428.             -? --help -t --test -v --verbose --version' -- $cur ) )
  7429.     else
  7430.         _volumegroups
  7431.     fi
  7432. }
  7433. complete -F _vgrename vgrename
  7434.  
  7435. _vgreduce()
  7436. {
  7437.     local cur prev
  7438.  
  7439.     COMPREPLY=()
  7440.     cur=${COMP_WORDS[COMP_CWORD]}
  7441.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7442.  
  7443.     case "$prev" in
  7444.         -@(A|-autobackup))
  7445.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7446.             return 0
  7447.             ;;
  7448.     esac
  7449.  
  7450.     if [[ "$cur" == -* ]]; then
  7451.         COMPREPLY=( $( compgen -W '-a --all -A --autobackup -d \
  7452.             --debug -h --help --removemissing -t --test -v \
  7453.             --verbose --version' -- $cur ) )
  7454.  
  7455.     else
  7456.         _args
  7457.         if [ $args -eq 0 ]; then
  7458.             _volumegroups
  7459.         else
  7460.             _physicalvolumes
  7461.         fi
  7462.     fi
  7463. }
  7464. complete -F _vgreduce vgreduce
  7465.  
  7466. _vgextend()
  7467. {
  7468.     local cur prev
  7469.  
  7470.     COMPREPLY=()
  7471.     cur=${COMP_WORDS[COMP_CWORD]}
  7472.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7473.  
  7474.     case "$prev" in
  7475.         -@(A|-autobackup))
  7476.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7477.             return 0
  7478.             ;;
  7479.         -@(L|-size))
  7480.             _sizes
  7481.             return 0
  7482.             ;;
  7483.     esac
  7484.  
  7485.     if [[ "$cur" == -* ]]; then
  7486.         COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -h \
  7487.             -? --help -t --test -v --verbose --version' -- $cur ) )
  7488.     else
  7489.         _args
  7490.         if [ $args -eq 0 ]; then
  7491.             _volumegroups
  7492.         else
  7493.             _physicalvolumes
  7494.         fi
  7495.     fi
  7496. }
  7497. complete -F _vgextend vgextend
  7498.  
  7499. _vgport()
  7500. {
  7501.     local cur prev
  7502.  
  7503.     COMPREPLY=()
  7504.     cur=${COMP_WORDS[COMP_CWORD]}
  7505.  
  7506.     if [[ "$cur" == -* ]]; then
  7507.         COMPREPLY=( $( compgen -W '-a --all -d --debug -h \
  7508.             -? --help -v --verbose --version' -- $cur ) )
  7509.     else
  7510.         _volumegroups
  7511.     fi
  7512. }
  7513. complete -F _vgport vgimport vgexport
  7514.  
  7515. _vgck()
  7516. {
  7517.     local cur prev
  7518.  
  7519.     COMPREPLY=()
  7520.     cur=${COMP_WORDS[COMP_CWORD]}
  7521.  
  7522.     if [[ "$cur" == -* ]]; then
  7523.         COMPREPLY=( $( compgen -W '-d --debug -h \
  7524.             -? --help -v --verbose --version' -- $cur ) )
  7525.     else
  7526.         _volumegroups
  7527.     fi
  7528. }
  7529. complete -F _vgck vgck
  7530.  
  7531. _vgconvert()
  7532. {
  7533.     local cur prev
  7534.  
  7535.     COMPREPLY=()
  7536.     cur=${COMP_WORDS[COMP_CWORD]}
  7537.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7538.  
  7539.     case "$prev" in
  7540.         -@(M|-metadatatype))
  7541.             COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
  7542.             return 0
  7543.             ;;
  7544.         --metadatacopies)
  7545.             COMPREPLY=( $( compgen -W '0 1 2' -- $cur ) )
  7546.             return 0
  7547.             ;;
  7548.         --metadatasize)
  7549.             _sizes
  7550.             return 0
  7551.             ;;
  7552.     esac
  7553.  
  7554.     if [[ "$cur" == -* ]]; then
  7555.         COMPREPLY=( $( compgen -W '-d --debug -h --help --labelsector \ 
  7556.             -M --metadatatype --metadatacopies --metadatasize \
  7557.             -t --test -v --verbose --version' -- $cur ) )
  7558.     else
  7559.         _volumegroups
  7560.     fi
  7561. }
  7562. complete -F _vgconvert vgconvert
  7563.  
  7564. _vgcfgbackup()
  7565. {
  7566.     local cur prev
  7567.  
  7568.     COMPREPLY=()
  7569.     cur=${COMP_WORDS[COMP_CWORD]}
  7570.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7571.  
  7572.     case "$prev" in
  7573.         -@(f|-file))
  7574.             _filedir
  7575.             return 0
  7576.             ;;
  7577.     esac
  7578.  
  7579.     if [[ "$cur" == -* ]]; then
  7580.         COMPREPLY=( $( compgen -W '-d --debug -f --file -h --help \
  7581.             --ignorelockingfailure -P --partial -v --verbose \
  7582.             --version' -- $cur ) )
  7583.     else
  7584.         _volumegroups
  7585.     fi
  7586. }
  7587. complete -F _vgcfgbackup vgcfgbackup
  7588.  
  7589. _vgcfgrestore()
  7590. {
  7591.     local cur prev
  7592.  
  7593.     COMPREPLY=()
  7594.     cur=${COMP_WORDS[COMP_CWORD]}
  7595.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7596.  
  7597.     case "$prev" in
  7598.         -@(f|-file))
  7599.             _filedir
  7600.             return 0
  7601.             ;;
  7602.         -@(M|-metadatatype))
  7603.             COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
  7604.             return 0
  7605.             ;;
  7606.         -@(n|-name))
  7607.             _volumegroups
  7608.             return 0
  7609.             ;;
  7610.     esac
  7611.  
  7612.     if [[ "$cur" == -* ]]; then
  7613.         COMPREPLY=( $( compgen -W '-d --debug -f --file -l --list \
  7614.             -h --help -M --Metadatatype -n --name -t --test \
  7615.             -v --verbose --version' -- $cur ) )
  7616.     else
  7617.         _volumegroups
  7618.     fi
  7619. }
  7620. complete -F _vgcfgrestore vgcfgrestore
  7621.  
  7622. _vgmerge()
  7623. {
  7624.     local cur prev
  7625.  
  7626.     COMPREPLY=()
  7627.     cur=${COMP_WORDS[COMP_CWORD]}
  7628.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7629.  
  7630.     case "$prev" in
  7631.         -@(A|-autobackup))
  7632.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7633.             return 0
  7634.             ;;
  7635.     esac
  7636.  
  7637.     if [[ "$cur" == -* ]]; then
  7638.         COMPREPLY=( $( compgen -W '-A --autobackup -d --debug \
  7639.             -h --help -l --list -t --test -v --verbose \
  7640.             --version' -- $cur ) )
  7641.     else
  7642.         _volumegroups
  7643.     fi
  7644. }
  7645. complete -F _vgmerge vgmerge
  7646.  
  7647. _vgsplit()
  7648. {
  7649.     local cur prev
  7650.  
  7651.     COMPREPLY=()
  7652.     cur=${COMP_WORDS[COMP_CWORD]}
  7653.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7654.  
  7655.     case "$prev" in
  7656.         -@(A|-autobackup))
  7657.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7658.             return 0
  7659.             ;;
  7660.         -@(M|-metadatatype))
  7661.             COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
  7662.             return 0
  7663.             ;;
  7664.     esac
  7665.  
  7666.     if [[ "$cur" == -* ]]; then
  7667.         COMPREPLY=( $( compgen -W '-A --autobackup -d --debug \
  7668.             -h --help -l --list -M --metadatatype -t --test \
  7669.             -v --verbose --version' -- $cur ) )
  7670.     else
  7671.         _args
  7672.         if [ $args -eq 0 -o $args -eq 1 ]; then
  7673.             _volumegroups
  7674.         else
  7675.             _physicalvolumes
  7676.         fi
  7677.     fi
  7678. }
  7679. complete -F _vgsplit vgsplit
  7680.  
  7681. _vgmknodes()
  7682. {
  7683.     local cur
  7684.  
  7685.     COMPREPLY=()
  7686.     cur=${COMP_WORDS[COMP_CWORD]}
  7687.  
  7688.     if [[ "$cur" == -* ]]; then
  7689.         COMPREPLY=( $( compgen -W '-d --debug -h --help -v --verbose \
  7690.             --version' -- $cur ) )
  7691.     else
  7692.         _volumegroups
  7693.     fi
  7694. }
  7695. complete -F _vgmknodes vgmknodes
  7696.  
  7697. _lvscan()
  7698. {
  7699.     local cur
  7700.  
  7701.     COMPREPLY=()
  7702.     cur=${COMP_WORDS[COMP_CWORD]}
  7703.  
  7704.     if [[ "$cur" == -* ]]; then
  7705.         COMPREPLY=( $( compgen -W '-b --blockdevice -d --debug \
  7706.             -h -? --help --ignorelockingfailure -P \
  7707.             --partial -v --verbose --version' -- $cur ) )
  7708.     fi
  7709. }
  7710. complete -F _lvscan lvscan
  7711.  
  7712. _lvs()
  7713. {
  7714.     local cur prev
  7715.  
  7716.     COMPREPLY=()
  7717.     cur=${COMP_WORDS[COMP_CWORD]}
  7718.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7719.  
  7720.     case "$prev" in
  7721.         -@(o|O|-options|-sort))
  7722.             COMPREPLY=( $( compgen -W 'lv_uuid lv_name \
  7723.                 lv_attr lv_minor lv_size seg_count \
  7724.                 origin snap_percent segtype stripes \
  7725.                 stripesize chunksize seg_start \
  7726.                 seg_size' -- $cur ) )
  7727.             return 0
  7728.             ;;
  7729.         --units)
  7730.             _units
  7731.             return 0
  7732.             ;;
  7733.     esac
  7734.  
  7735.     if [[ "$cur" == -* ]]; then
  7736.         COMPREPLY=( $( compgen -W '--aligned -d --debug \
  7737.             -h --help --ignorelockingfailure --noheadings \
  7738.             --nosuffix -o --options -O --sort -P --partial \
  7739.             --segments --separator --unbuffered --units \
  7740.             -v --verbose --version' -- $cur ) )
  7741.     else
  7742.         _logicalvolumes
  7743.     fi
  7744. }
  7745. complete -F _lvs lvs
  7746.  
  7747. _lvdisplay()
  7748. {
  7749.     local cur prev
  7750.  
  7751.     COMPREPLY=()
  7752.     cur=${COMP_WORDS[COMP_CWORD]}
  7753.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7754.  
  7755.     case "$prev" in
  7756.         --units)
  7757.             _units
  7758.             return 0
  7759.             ;;
  7760.     esac
  7761.  
  7762.     if [[ "$cur" == -* ]]; then
  7763.         COMPREPLY=( $( compgen -W '-c --colon -C --columns --units \
  7764.             -P --partial -m --maps -v --verbose -d --debug -h \
  7765.             --help --version' -- $cur ) )
  7766.     else
  7767.         _logicalvolumes
  7768.     fi
  7769. }
  7770. complete -F _lvdisplay lvdisplay
  7771.  
  7772. _lvchange()
  7773. {
  7774.     local cur prev
  7775.  
  7776.     COMPREPLY=()
  7777.     cur=${COMP_WORDS[COMP_CWORD]}
  7778.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7779.  
  7780.     case "$prev" in
  7781.         -@(a|A|C|M|-available|-autobackup|-continguous|-persistent))
  7782.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7783.             return 0
  7784.             ;;
  7785.         -@(p|-permission))
  7786.             COMPREPLY=( $( compgen -W 'r rw' -- $cur ) )
  7787.             return 0
  7788.             ;;
  7789.     esac
  7790.  
  7791.     if [[ "$cur" == -* ]]; then
  7792.         COMPREPLY=( $( compgen -W '-A --autobackup -a --available \
  7793.             --addtag --alloc -C --contiguous -d --debug --deltag \
  7794.             -f --force -h --help --ignorelockingfailure -M \
  7795.             --persistent --major major --minor minor -P --partial \
  7796.             -p --permission -r --readahead --refresh -t --test \
  7797.             -v --verbose --version' -- $cur ) )
  7798.     else
  7799.         _logicalvolumes
  7800.     fi
  7801. }
  7802. complete -F _lvchange lvchange
  7803.  
  7804. _lvcreate()
  7805. {
  7806.     local cur prev
  7807.  
  7808.     COMPREPLY=()
  7809.     cur=${COMP_WORDS[COMP_CWORD]}
  7810.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7811.  
  7812.     case "$prev" in
  7813.         -@(A|C|M|Z|-autobackup|-continguous|-persistent|-zero))
  7814.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7815.             return 0
  7816.             ;;
  7817.         -@(L|-size))
  7818.             _sizes
  7819.             return 0
  7820.             ;;
  7821.         -@(p|-permission))
  7822.             COMPREPLY=( $( compgen -W 'r rw' -- $cur ) )
  7823.             return 0
  7824.             ;;
  7825.         -@(n|-name))
  7826.             _logicalvolumes
  7827.             return 0
  7828.             ;;
  7829.     esac
  7830.  
  7831.     if [[ "$cur" == -* ]]; then
  7832.         COMPREPLY=( $( compgen -W '-A --autobackup --addtag --alloc \
  7833.             -C --contiguous -d --debug -h -? --help -i --stripes \
  7834.             -I --stripesize -l --extents -L --size -M --persistent \
  7835.             --major --minor -n --name -p --permission -r \
  7836.             --readahead -t --test --type -v --verbose -Z --zero \
  7837.             --version' -- $cur ) )
  7838.     else
  7839.         _args
  7840.         if [ $args -eq 0 ]; then
  7841.             _volumegroups
  7842.         else
  7843.             _physicalvolumes
  7844.         fi
  7845.     fi
  7846. }
  7847. complete -F _lvcreate lvcreate
  7848.  
  7849. _lvremove()
  7850. {
  7851.     local cur prev
  7852.  
  7853.     COMPREPLY=()
  7854.     cur=${COMP_WORDS[COMP_CWORD]}
  7855.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7856.  
  7857.     case "$prev" in
  7858.         -@(A|-autobackup))
  7859.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7860.             return 0
  7861.             ;;
  7862.     esac
  7863.  
  7864.     if [[ "$cur" == -* ]]; then
  7865.         COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -f \
  7866.             --force -h -?  --help -t --test -v --verbose \
  7867.             --version' -- $cur ) )
  7868.     else
  7869.         _logicalvolumes
  7870.     fi
  7871. }
  7872. complete -F _lvremove lvremove
  7873.  
  7874. _lvrename()
  7875. {
  7876.     local cur prev
  7877.  
  7878.     COMPREPLY=()
  7879.     cur=${COMP_WORDS[COMP_CWORD]}
  7880.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7881.  
  7882.     case "$prev" in
  7883.         -@(A|-autobackup))
  7884.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7885.             return 0
  7886.             ;;
  7887.     esac
  7888.  
  7889.     if [[ "$cur" == -* ]]; then
  7890.         COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -h \
  7891.             -? --help -t --test -v --verbose --version' -- $cur ) )
  7892.     else
  7893.         _logicalvolumes
  7894.     fi
  7895. }
  7896. complete -F _lvrename lvrename
  7897.  
  7898. _lvreduce()
  7899. {
  7900.     local cur prev
  7901.  
  7902.     COMPREPLY=()
  7903.     cur=${COMP_WORDS[COMP_CWORD]}
  7904.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7905.  
  7906.     case "$prev" in
  7907.         -@(A|-autobackup))
  7908.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7909.             return 0
  7910.             ;;
  7911.         -@(L|-size))
  7912.             _sizes
  7913.             return 0
  7914.             ;;
  7915.     esac
  7916.  
  7917.     if [[ "$cur" == -* ]]; then
  7918.         COMPREPLY=( $( compgen -W '-A --autobackup -d \
  7919.             --debug -f --force -h --help -l --extents \
  7920.             -L --size -n --nofsck -r --resizefs -t --test \
  7921.             -v --verbose --version' -- $cur ) )
  7922.     else
  7923.         _logicalvolumes
  7924.     fi
  7925. }
  7926. complete -F _lvreduce lvreduce
  7927.  
  7928. _lvresize()
  7929. {
  7930.     local cur prev
  7931.  
  7932.     COMPREPLY=()
  7933.     cur=${COMP_WORDS[COMP_CWORD]}
  7934.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7935.  
  7936.     case "$prev" in
  7937.         -@(A|-autobackup))
  7938.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7939.             return 0
  7940.             ;;
  7941.         -@(L|-size))
  7942.             _sizes
  7943.             return 0
  7944.             ;;
  7945.     esac
  7946.  
  7947.     if [[ "$cur" == -* ]]; then
  7948.         COMPREPLY=( $( compgen -W '-A --autobackup --alloc -d \
  7949.             --debug -h --help -i --stripes -I --stripesize \
  7950.             -l --extents -L --size -n --nofsck -r --resizefs \
  7951.             -t --test --type -v --verbose --version' -- $cur ) )
  7952.     else
  7953.         _args
  7954.         if [ $args -eq 0 ]; then
  7955.             _logicalvolumes
  7956.         else
  7957.             _physicalvolumes
  7958.         fi
  7959.     fi
  7960. }
  7961. complete -F _lvresize lvresize
  7962.  
  7963. _lvextend()
  7964. {
  7965.     local cur prev
  7966.  
  7967.     COMPREPLY=()
  7968.     cur=${COMP_WORDS[COMP_CWORD]}
  7969.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7970.  
  7971.     case "$prev" in
  7972.         -@(A|-autobackup))
  7973.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7974.             return 0
  7975.             ;;
  7976.         -@(L|-size))
  7977.             _sizes
  7978.             return 0
  7979.             ;;
  7980.     esac
  7981.  
  7982.     if [[ "$cur" == -* ]]; then
  7983.         COMPREPLY=( $( compgen -W '-A --autobackup --alloc -d \
  7984.             --debug -h --help -i --stripes -I --stripesize \
  7985.             -l --extents -L --size -n --nofsck -r --resizefs \
  7986.             -t --test --type -v --verbose --version' -- $cur ) )
  7987.     else
  7988.         _args
  7989.         if [ $args -eq 0 ]; then
  7990.             _logicalvolumes
  7991.         else
  7992.             _physicalvolumes
  7993.         fi
  7994.     fi
  7995. }
  7996. complete -F _lvextend lvextend
  7997.  
  7998. _lvm()
  7999. {
  8000.     local prev
  8001.  
  8002.     COMPREPLY=()
  8003.     cur=${COMP_WORDS[COMP_CWORD]}
  8004.  
  8005.     if [ $COMP_CWORD -eq 1 ]; then
  8006.         COMPREPLY=( $( compgen -W 'dumpconfig help lvchange \
  8007.             lvcreate lvdisplay lvextend lvmchange \
  8008.             lvmdiskscan lvmsadc lvmsar lvreduce \
  8009.             lvremove lvrename lvresize lvs lvscan \
  8010.             pvchange pvcreate pvdata pvdisplay pvmove \
  8011.             pvremove pvresize pvs pvscan vgcfgbackup \
  8012.             vgcfgrestore vgchange vgck vgconvert \
  8013.             vgcreate vgdisplay vgexport vgextend \
  8014.             vgimport vgmerge vgmknodes vgreduce \
  8015.             vgremove vgrename vgs vgscan vgsplit \
  8016.             version' -- $cur ) )
  8017.     else
  8018.         case ${COMP_WORDS[1]} in
  8019.             pvchange)
  8020.                 _pvchange
  8021.                 ;;
  8022.             pvcreate)
  8023.                 _pvcreate
  8024.                 ;;
  8025.             pvdisplay)
  8026.                 _pvdisplay
  8027.                 ;;
  8028.             pvmove)
  8029.                 _pvmove
  8030.                 ;;
  8031.             pvremove)
  8032.                 _pvremove
  8033.                 ;;
  8034.             pvresize)
  8035.                 _pvresize
  8036.                 ;;
  8037.             pvs)
  8038.                 _pvs
  8039.                 ;;
  8040.             pvscan)
  8041.                 _pvscan
  8042.                 ;;
  8043.             vgcfgbackup)
  8044.                 _vgcfgbackup
  8045.                 ;;
  8046.             vgcfgrestore)
  8047.                 _vgcfgrestore
  8048.                 ;;
  8049.             vgchange)
  8050.                 _vgchange
  8051.                 ;;
  8052.             vgck)
  8053.                 _vgck
  8054.                 ;;
  8055.             vgconvert)
  8056.                 _vgconvert
  8057.                 ;;
  8058.             vgcreate)
  8059.                 _vgcreate
  8060.                 ;;
  8061.             vgdisplay)
  8062.                 _vgdisplay
  8063.                 ;;
  8064.             vgexport)
  8065.                 _vgexport
  8066.                 ;;
  8067.             vgextend)
  8068.                 _vgextend
  8069.                 ;;
  8070.             vgimport)
  8071.                 _vgimport
  8072.                 ;;
  8073.             vgmerge)
  8074.                 _vgmerge
  8075.                 ;;
  8076.             vgmknodes)
  8077.                 _vgmknodes
  8078.                 ;;
  8079.             vgreduce)
  8080.                 _vgreduce
  8081.                 ;;
  8082.             vgremove)
  8083.                 _vgremove
  8084.                 ;;
  8085.             vgrename)
  8086.                 _vgrename
  8087.                 ;;
  8088.             vgs)
  8089.                 _vgs
  8090.                 ;;
  8091.             vgscan)
  8092.                 _vgscan
  8093.                 ;;
  8094.             vgsplit)
  8095.                 _vgsplit
  8096.                 ;;
  8097.             lvchange)
  8098.                 _lvchange
  8099.                 ;;
  8100.             lvcreate)
  8101.                 _lvcreate
  8102.                 ;;
  8103.             lvdisplay)
  8104.                 _lvdisplay
  8105.                 ;;
  8106.             lvextend)
  8107.                 _lvextend
  8108.                 ;;
  8109.             lvreduce)
  8110.                 _lvreduce
  8111.                 ;;
  8112.             lvremove)
  8113.                 _lvremove
  8114.                 ;;
  8115.             lvrename)
  8116.                 _lvrename
  8117.                 ;;
  8118.             lvresize)
  8119.                 _lvresize
  8120.                 ;;
  8121.             lvs)
  8122.                 _lvs
  8123.                 ;;
  8124.             lvscan)
  8125.                 _lvscan
  8126.                 ;;
  8127.         esac
  8128.     fi
  8129. }
  8130. complete -F _lvm lvm
  8131. }
  8132.  
  8133. # mkinitrd(8) completion
  8134. #
  8135. have mkinitrd &&
  8136. _mkinitrd()
  8137. {
  8138.     local cur args
  8139.  
  8140.     COMPREPLY=()
  8141.     cur=${COMP_WORDS[COMP_CWORD]}
  8142.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8143.  
  8144.     # --name value style option
  8145.     case "$prev" in
  8146.         --preload)
  8147.             _modules
  8148.             return 0
  8149.             ;;
  8150.     esac
  8151.  
  8152.     # --name=value style option
  8153.     if [[ "$cur" == *=* ]]; then
  8154.         prev=${cur/=*/}
  8155.         cur=${cur/*=/}
  8156.         case "$prev" in
  8157.             --@(with|builtin))
  8158.                 _modules
  8159.                 return 0
  8160.                 ;;
  8161.             --@(fstab|dsdt))
  8162.                 _filedir
  8163.                 return 0
  8164.                 ;;
  8165.             --tmpdir)
  8166.                 _filedir -d
  8167.                 return 0
  8168.                 ;;
  8169.         esac
  8170.     fi
  8171.  
  8172.  
  8173.     if [[ "$cur" == -* ]]; then
  8174.         COMPREPLY=( $( compgen -W '--version -v -f --preload \
  8175.             --with= --omit-scsi-modules --omit-raid-modules \
  8176.             --images-version --fstab= --nocompress --builtin= \
  8177.             --nopivot --noudev --allow-missing --tmpdir= \
  8178.             --initrdfs= --dsdt= --lvm-version= --froce-usb' \
  8179.             -- $cur ) )
  8180.     else
  8181.         _count_args
  8182.  
  8183.         case $args in
  8184.             1)
  8185.                 _filedir
  8186.                 ;;
  8187.             2)
  8188.                 COMPREPLY=( $( command ls /lib/modules | grep "^$cur" ) )
  8189.                 ;;
  8190.         esac
  8191.     fi
  8192.  
  8193. } &&
  8194. complete -F _mkinitrd mkinitrd
  8195.  
  8196. # pkgconfig(1) completion
  8197. #
  8198. have pkg-config &&
  8199. _pkg_config()
  8200. {
  8201.     local cur
  8202.  
  8203.     COMPREPLY=()
  8204.     cur=${COMP_WORDS[COMP_CWORD]}
  8205.  
  8206.     if [[ "$cur" == -* ]]; then
  8207.         # return list of available options
  8208.         COMPREPLY=( $( compgen -W '-version --modversion \
  8209.               --atleast-pkgconfig-version= --libs --libs-only-l \
  8210.               --libs-only-other --libs-only-L --cflags \
  8211.               --cflags-only-I --cflags-only-other --variable= \
  8212.               --define-variable= --exists --uninstalled \
  8213.               --atleast-version= --exact-version= --max-version= \
  8214.               --list-all --debug --print-errors --silence-errors \
  8215.               --errors-to-stdout -? --help --usage' -- $cur))
  8216.     else
  8217.         COMPREPLY=( $( pkg-config --list-all 2>/dev/null | \
  8218.                     awk '{print $1}' | grep "^$cur" ) )
  8219.     fi
  8220. } &&
  8221. complete -F _pkg_config pkg-config
  8222.  
  8223.  
  8224. # cpio(1) completion
  8225. #
  8226. have cpio && {
  8227. _cpio_format()
  8228. {
  8229.     COMPREPLY=( $( compgen -W 'bin odc newc crc tar ustar hpbin hpodc' -- $cur ) )
  8230. }
  8231.  
  8232. _cpio()
  8233. {
  8234.     local cur
  8235.  
  8236.     COMPREPLY=()
  8237.     cur=${COMP_WORDS[COMP_CWORD]}
  8238.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8239.  
  8240.     # --name value style option
  8241.     case $prev in
  8242.         -H)
  8243.             _cpio_format
  8244.             return 0
  8245.             ;;
  8246.         -@(E|F|I))
  8247.             _filedir
  8248.             return 0
  8249.             ;;
  8250.         -R)
  8251.             _usergroup
  8252.             return 0
  8253.             ;;
  8254.     esac
  8255.  
  8256.     # --name=value style option
  8257.     if [[ "$cur" == *=* ]]; then
  8258.         prev=${cur/=*/}
  8259.         cur=${cur/*=/}
  8260.         case $prev in
  8261.             --format)
  8262.                 _cpio_format
  8263.                 return 0
  8264.                 ;;
  8265.             --@(file|pattern-file))
  8266.                 _filedir
  8267.                 return 0
  8268.                 ;;
  8269.             --owner)
  8270.                 _usergroup
  8271.                 return 0
  8272.                 ;;
  8273.             --rsh-command)
  8274.                 COMPREPLY=( $( compgen -c -- $cur ) )
  8275.                 return 0
  8276.                 ;;
  8277.         esac
  8278.     fi
  8279.  
  8280.     if [ $COMP_CWORD -eq 1 ]; then
  8281.         COMPREPLY=( $( compgen -W '-o --create -i --extract -p --pass-through' -- $cur) ) 
  8282.     else
  8283.         case ${COMP_WORDS[1]} in
  8284.             -@(o|-create))
  8285.                 if [[ "$cur" == -* ]]; then
  8286.                     COMPREPLY=( $( compgen -W '-0 -a -c -v -A -B\
  8287.                         -L -V -C -H -M -O -F --file= --format=\
  8288.                         --message= --null --reset-access-time\
  8289.                         --verbose --dot --append --block-size=\
  8290.                         --dereference --io-size= --quiet\
  8291.                         --force-local --rsh-command= --help\
  8292.                         --version' -- $cur ) )
  8293.                 fi
  8294.                 ;;
  8295.             -@(i|-extract))
  8296.                 if [[ "$cur" == -* ]]; then
  8297.                     COMPREPLY=( $( compgen -W '-b -c -d -f -m -n -r\
  8298.                         -t -s -u -v -B -S -V -C -E -H -M -R -I\
  8299.                         -F --file= --make-directories\
  8300.                         --nonmatching\
  8301.                         --preserve-modification-time\
  8302.                         --numeric-uid-gid --rename -t --list\
  8303.                         --swap-bytes --swap --dot\
  8304.                         --unconditional --verbose --block-size=\
  8305.                         --swap-halfwords --io-size=\
  8306.                         --pattern-file= --format= --owner=\
  8307.                         --no-preserve-owner --message=\
  8308.                         --force-local --no-absolute-filenames\
  8309.                         --sparse --only-verify-crc --quiet\
  8310.                         --rsh-command= --help\
  8311.                         --version' -- $cur ) )
  8312.                 fi
  8313.                 ;;
  8314.             -@(p|-pass-through))
  8315.                 if [[ "$cur" == -* ]]; then
  8316.                     COMPREPLY=( $( compgen -W '-0 -a -d -l -m -u -v\
  8317.                         -L -V -R --null --reset-access-time\
  8318.                         --make-directories --link --quiet\
  8319.                         --preserve-modification-time\
  8320.                         --unconditional --verbose --dot\
  8321.                         --dereference --owner=\
  8322.                         --no-preserve-owner --sparse --help\
  8323.                         --version' -- $cur ) )
  8324.                 else
  8325.                     _filedir -d
  8326.                 fi
  8327.                 ;;
  8328.         esac
  8329.     fi
  8330. }
  8331. complete -F _cpio cpio
  8332. }
  8333.  
  8334. # id(1) completion
  8335. #
  8336. have id &&
  8337. _id()
  8338. {
  8339.     local cur
  8340.  
  8341.     COMPREPLY=()
  8342.     cur=${COMP_WORDS[COMP_CWORD]}
  8343.  
  8344.     if [[ "$cur" == -* ]]; then
  8345.         COMPREPLY=( $( compgen -W '-a -g --group -G --groups -n --name\
  8346.             -r --real -u --user --help --version' -- $cur ) )
  8347.     else
  8348.         COMPREPLY=( $( compgen -u $cur  ) )
  8349.     fi
  8350. } &&
  8351. complete -F _id id
  8352.  
  8353. # getent(1) completion
  8354. #
  8355. have getent &&
  8356. _getent()
  8357. {
  8358.     local cur prev
  8359.  
  8360.     COMPREPLY=()
  8361.     cur=${COMP_WORDS[COMP_CWORD]}
  8362.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8363.  
  8364.     case $prev in
  8365.         passwd)
  8366.             COMPREPLY=( $( compgen -u $cur  ) )
  8367.             return 0
  8368.             ;;
  8369.         group)
  8370.             COMPREPLY=( $( compgen -g $cur  ) )
  8371.             return 0
  8372.             ;;
  8373.         services)
  8374.             COMPREPLY=( $( compgen -s $cur  ) )
  8375.             return 0
  8376.             ;;
  8377.         hosts)
  8378.             COMPREPLY=( $( compgen -A hostname $cur  ) )
  8379.             return 0
  8380.             ;;
  8381.         protocols)
  8382.             COMPREPLY=( $( getent protocols | awk '{print $1}' | grep "^$cur" ) )
  8383.             return 0
  8384.             ;;
  8385.         networks)
  8386.             COMPREPLY=( $( getent networks | awk '{print $1}' | grep "^$cur" ) )
  8387.             return 0
  8388.             ;;
  8389.     esac
  8390.  
  8391.  
  8392.     if [ $COMP_CWORD -eq 1 ]; then
  8393.         COMPREPLY=( $( compgen -W 'passwd group hosts services protocols networks' -- $cur ) )
  8394.     fi
  8395. } &&
  8396. complete -F _getent getent
  8397.  
  8398. # ntpdate(1) completion
  8399. #
  8400. have ntpdate &&
  8401. _ntpdate()
  8402. {
  8403.     local cur prev
  8404.  
  8405.     COMPREPLY=()
  8406.     cur=${COMP_WORDS[COMP_CWORD]}
  8407.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8408.  
  8409.     case $prev in
  8410.         -k)
  8411.             _filedir
  8412.             return 0
  8413.             ;;
  8414.         -U)
  8415.             COMPREPLY=( $( compgen -u $cur  ) )
  8416.             return 0
  8417.             ;;
  8418.     esac
  8419.  
  8420.     if [[ "$cur" == -* ]]; then
  8421.         COMPREPLY=( $( compgen -W '-4 -6 -b -B -d -Q -q -s -u -v -a\
  8422.             -e -k -p -o -r -t' -- $cur ) )
  8423.     else
  8424.         _known_hosts
  8425.     fi
  8426. } &&
  8427. complete -F _ntpdate ntpdate
  8428.  
  8429. # smartctl(8) completion
  8430. #
  8431. have smartctl && {
  8432. _smartctl_quietmode()
  8433. {
  8434.     COMPREPLY=( $( compgen -W 'errorsonly silent' -- $cur ) )
  8435. }
  8436. _smartctl_device()
  8437. {
  8438.     COMPREPLY=( $( compgen -W 'ata scsi 3ware' -- $cur ) )
  8439. }
  8440. _smartctl_tolerance()
  8441. {
  8442.     COMPREPLY=( $( compgen -W 'warn exit ignore' -- $cur ) )
  8443. }
  8444. _smartctl_badsum()
  8445. {
  8446.     COMPREPLY=( $( compgen -W 'normal conservative permissive verypermissive' -- $cur ) )
  8447. }
  8448. _smartctl_report()
  8449. {
  8450.     COMPREPLY=( $( compgen -W 'ioctl ataioctl scsiioctl' -- $cur ) )
  8451. }
  8452. _smartctl_feature()
  8453. {
  8454.     COMPREPLY=( $( compgen -W 'on off' -- $cur ) )
  8455. }
  8456. _smartctl_log()
  8457. {
  8458.     COMPREPLY=( $( compgen -W 'error selftest selective directory' -- $cur ) )
  8459. }
  8460. _smartctl_vendorattribute()
  8461. {
  8462.     COMPREPLY=( $( compgen -W 'help 9,minutes 9,seconds 9,halfminutes \
  8463.         9,temp 192,emergencyretractcyclect 193,loadunload \
  8464.         194,10xCelsius 194,unknown 198,offlinescanuncsectorct \
  8465.         200,writeerrorcount 201,detectedtacount 220,temp' -- $cur ) )
  8466. }
  8467. _smartctl_firmwarebug()
  8468. {
  8469.     COMPREPLY=( $( compgen -W 'none samsung samsung2' -- $cur ) )
  8470. }
  8471. _smartctl_presets()
  8472. {
  8473.     COMPREPLY=( $( compgen -W 'use ignore show showall' -- $cur ) )
  8474. }
  8475. _smartctl_test()
  8476. {
  8477.     COMPREPLY=( $( compgen -W 'offline short long conveyance select afterselect,on afterselect,off pending' -- $cur ) )
  8478. }
  8479.  
  8480. _smartctl()
  8481. {
  8482.     local cur prev
  8483.  
  8484.     COMPREPLY=()
  8485.     cur=${COMP_WORDS[COMP_CWORD]}
  8486.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8487.  
  8488.     # --name value style option
  8489.     case "$prev" in
  8490.         -q)
  8491.             _smartctl_quietmode
  8492.             ;;
  8493.         -d)
  8494.             _smartctl_device
  8495.             return 0
  8496.             ;;
  8497.         -t)
  8498.             _smartctl_tolerance
  8499.             return 0
  8500.             ;;
  8501.         -b)
  8502.             _smartctl_badsum
  8503.             return 0
  8504.             ;;
  8505.         -r)
  8506.             _smartctl_report
  8507.             return 0
  8508.             ;;
  8509.         -s)
  8510.             _smartctl_feature
  8511.             return 0
  8512.             ;;
  8513.         -o)
  8514.             _smartctl_feature
  8515.             return 0
  8516.             ;;
  8517.         -S)
  8518.             _smartctl_feature
  8519.             return 0
  8520.             ;;
  8521.         -l)
  8522.             _smartctl_log
  8523.             return 0
  8524.             ;;
  8525.         -v)
  8526.             _smartctl_vendorattribute
  8527.             return 0
  8528.             ;;
  8529.         -F)
  8530.             _smartctl_firmwarebug
  8531.             return 0
  8532.             ;;
  8533.         -P)
  8534.             _smartctl_presets
  8535.             return 0
  8536.             ;;
  8537.         -t)
  8538.             _smartctl_test
  8539.             return 0
  8540.             ;;
  8541.     esac
  8542.  
  8543.     # --name=value style option
  8544.     if [[ "$cur" == *=* ]]; then
  8545.         prev=${cur/=*/}
  8546.         cur=${cur/*=/}
  8547.         case "$prev" in
  8548.             --quietmode)
  8549.                 _smartctl_quietmode
  8550.                 return 0
  8551.                 ;;
  8552.             --device)
  8553.                 _smartctl_device
  8554.                 return 0
  8555.                 ;;
  8556.             --tolerance)
  8557.                 _smartctl_tolerance
  8558.                 return 0
  8559.                 ;;
  8560.             --badsum)
  8561.                 _smartctl_badsum
  8562.                 return 0
  8563.                 ;;
  8564.             --report)
  8565.                 _smartctl_report
  8566.                 return 0
  8567.                 ;;
  8568.             --smart)
  8569.                 _smartctl_feature
  8570.                 return 0
  8571.                 ;;
  8572.             --offlineauto)
  8573.                 _smartctl_feature
  8574.                 return 0
  8575.                 ;;
  8576.             --saveauto)
  8577.                 _smartctl_feature
  8578.                 return 0
  8579.                 ;;
  8580.             --log)
  8581.                 _smartctl_log
  8582.                 return 0
  8583.                 ;;
  8584.             --vendorattribute)
  8585.                 _smartctl_vendorattribute
  8586.                 return 0
  8587.                 ;;
  8588.             --firmwarebug)
  8589.                 _smartctl_firmwarebug
  8590.                 return 0
  8591.                 ;;
  8592.             --presets)
  8593.                 _smartctl_presets
  8594.                 return 0
  8595.                 ;;
  8596.             --test)
  8597.                 _smartctl_test
  8598.                 return 0
  8599.                 ;;
  8600.         esac
  8601.     fi
  8602.  
  8603.  
  8604.     if [[ "$cur" == -* ]]; then
  8605.         COMPREPLY=( $( compgen -W '-h --help --usage -V --version \
  8606.             --copyright --license-i --info -a --all -q \
  8607.             --quietmode= -d --device= -T --tolerance= -b --badsum= \
  8608.             -r --report= -s --smart= -o --offlineauto= -S \
  8609.             --saveauto= -H --health -c --capabilities -A \
  8610.             --attributes -l --log= -v --vendorattribute= -F \
  8611.             --firmwarebug= -P --presets= -t --test= -C \
  8612.             --captive -X --abort' -- $cur ) )
  8613.     else
  8614.         cur=${cur:=/dev/}
  8615.         _filedir
  8616.     fi
  8617. }
  8618. complete -F _smartctl smartctl
  8619. }
  8620.  
  8621. # vncviewer(1) completion
  8622. #
  8623. have vncviewer &&
  8624. _vncviewer()
  8625. {
  8626.     local cur prev
  8627.     local -a config
  8628.     
  8629.     COMPREPLY=()
  8630.     cur=${COMP_WORDS[COMP_CWORD]}
  8631.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8632.  
  8633.     case "$prev" in
  8634.     -via)
  8635.        _known_hosts -a
  8636.        ;;
  8637.     *)
  8638.        # ssh into the the server, find and ping the broadcast address, then
  8639.        # sort and show the results.
  8640.        COMPREPLY=( $( ssh -o 'Batchmode yes' $prev \
  8641.               "ping -bnc 4 255.255.255.255" 2>/dev/null | \
  8642.               awk -F ' ' '{print $4}' | \
  8643.               sort -n | uniq | egrep '[0-9]+\.[0-9]+\.' 2>/dev/null ) )
  8644.     esac
  8645.                                    
  8646.     return 0
  8647. } &&
  8648. complete -F _vncviewer vncviewer
  8649.  
  8650. # sysctl(8) completion
  8651. #
  8652. have sysctl &&
  8653. _sysctl()
  8654. {
  8655.     local cur
  8656.  
  8657.     COMPREPLY=()
  8658.     cur=${COMP_WORDS[COMP_CWORD]}
  8659.  
  8660.     COMPREPLY=( $( compgen -W "$(sysctl -N -a 2>/dev/null)" -- $cur ) )
  8661.  
  8662.     return 0
  8663. } &&
  8664. complete -F _sysctl sysctl
  8665.  
  8666. # update-rc.d(8) completion
  8667. #
  8668. # Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
  8669. #
  8670. have update-rc.d &&
  8671. _update_rc_d()
  8672. {
  8673.     local cur prev sysvdir services options valid_options
  8674.  
  8675.     cur=${COMP_WORDS[COMP_CWORD]}
  8676.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8677.  
  8678.     [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
  8679.     || sysvdir=/etc/init.d
  8680.  
  8681.     services=( $(echo $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm*)) )
  8682.     services=( ${services[@]#$sysvdir/} )
  8683.     options=( -f -n )
  8684.  
  8685.     if [[ $COMP_CWORD -eq 1 || "$prev" == -* ]]; then
  8686.     valid_options=( $( \
  8687.         echo "${COMP_WORDS[@]} ${options[@]}" \
  8688.         | tr " " "\n" \
  8689.         | sed -ne "/$( echo "${options[@]}" | sed "s/ /\\|/g" )/p" \
  8690.         | sort | uniq -u \
  8691.         ) )
  8692.     COMPREPLY=( $( compgen -W '${options[@]} ${services[@]}' \
  8693.         -X '$( echo ${COMP_WORDS[@]} | tr " " "|" )' -- $cur ) )
  8694.     elif [[ "$prev" == ?($( echo ${services[@]} | tr " " "|" )) ]]; then
  8695.     COMPREPLY=( $( compgen -W 'remove defaults start stop' -- $cur ) )
  8696.     elif [[ "$prev" == defaults && "$cur" == [0-9] ]]; then
  8697.     COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
  8698.     elif [[ "$prev" == defaults && "$cur" == [sk]?([0-9]) ]]; then
  8699.     COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
  8700.     elif [[ "$prev" == defaults && -z "$cur" ]]; then
  8701.     COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 s k )
  8702.     elif [[ "$prev" == ?(start|stop) ]]; then
  8703.     if [[ "$cur" == [0-9] || -z "$cur" ]]; then 
  8704.         COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
  8705.     elif [[ "$cur" == [0-9][0-9] ]]; then 
  8706.         COMPREPLY=( $cur )
  8707.     else
  8708.         COMPREPLY=()
  8709.     fi
  8710.     elif [[ "$prev" == ?([0-9][0-9]|[0-6S]) ]]; then
  8711.     if [[ -z "$cur" ]]; then
  8712.         if [[ $prev == [0-9][0-9] ]]; then
  8713.         COMPREPLY=( 0 1 2 3 4 5 6 S )
  8714.         else
  8715.         COMPREPLY=( 0 1 2 3 4 5 6 S . )
  8716.         fi
  8717.     elif [[ "$cur" == [0-6S.] ]]; then 
  8718.         COMPREPLY=( $cur )
  8719.     else
  8720.         COMPREPLY=()
  8721.     fi
  8722.     elif [[ "$prev" == "." ]]; then
  8723.     COMPREPLY=( $(compgen -W "start stop" -- $cur) )
  8724.     else
  8725.     COMPREPLY=()
  8726.     fi
  8727.  
  8728.     return 0
  8729. } &&
  8730. complete -F _update_rc_d update-rc.d
  8731.  
  8732. # invoke-rc.d(8) completion
  8733. #
  8734. # Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
  8735. #
  8736. have invoke-rc.d &&
  8737. _invoke_rc_d()
  8738. {
  8739.     local cur prev sysvdir services options valid_options
  8740.  
  8741.     cur=${COMP_WORDS[COMP_CWORD]}
  8742.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8743.  
  8744.     [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
  8745.     || sysvdir=/etc/init.d
  8746.  
  8747.     services=( $(echo $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm*)) )
  8748.     services=( ${services[@]#$sysvdir/} )
  8749.     options=( --help --quiet --force --try-anyway --disclose-deny --query --no-fallback )
  8750.  
  8751.     if [[ ($COMP_CWORD -eq 1) || ("$prev" == --* ) ]]; then
  8752.     valid_options=( $( \
  8753.         echo ${COMP_WORDS[@]} ${options[@]} \
  8754.         | tr " " "\n" \
  8755.         | sed -ne "/$( echo ${options[@]} | sed "s/ /\\\\|/g" )/p" \
  8756.         | sort | uniq -u \
  8757.         ) )
  8758.     COMPREPLY=( $( compgen -W '${valid_options[@]} ${services[@]}' -- \
  8759.         $cur ) )
  8760.     elif [ -x $sysvdir/$prev ]; then
  8761.     COMPREPLY=( $( compgen -W '`sed -ne "y/|/ /; \
  8762.                         s/^.*Usage:[ ]*[^ ]*[ ]*{*\([^}\"]*\).*$/\1/p" \
  8763.                         $sysvdir/$prev`' -- \
  8764.         $cur ) )
  8765.     else
  8766.     COMPREPLY=()
  8767.     fi
  8768.  
  8769.     return 0
  8770. } &&
  8771. complete -F _invoke_rc_d invoke-rc.d
  8772.  
  8773. # minicom(1) completion
  8774. #
  8775. have minicom &&
  8776. _minicom()
  8777. {
  8778.     local cur prev
  8779.  
  8780.     COMPREPLY=()
  8781.     cur=${COMP_WORDS[COMP_CWORD]}
  8782.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8783.  
  8784.     case $prev in
  8785.         -@(a|c))
  8786.             COMPREPLY=( $( compgen -W 'on off' -- $cur ) )
  8787.             return 0
  8788.             ;;
  8789.         -@(S|C))
  8790.             _filedir
  8791.             return 0
  8792.             ;;
  8793.         -P)
  8794.             COMPREPLY=( $( command ls /dev/tty* ) )
  8795.             COMPREPLY=( $( compgen -W '${COMPREPLY[@]} ${COMPREPLY[@]#/dev/}' -- $cur ) )
  8796.             return 0
  8797.             ;;
  8798.     esac
  8799.  
  8800.  
  8801.     if [[ "$cur" == -* ]]; then
  8802.         COMPREPLY=( $( compgen -W '-s -o -m -M -z -l -L -w -a -t \
  8803.             -c -S -d -p -C -T -8' -- $cur ) )
  8804.     else
  8805.         COMPREPLY=( $( command ls /etc/minicom/minirc.* 2>/dev/null | sed -e 's|/etc/minicom/minirc.||' | grep "^$cur" ) )
  8806.     fi
  8807. } &&
  8808. complete -F _minicom minicom
  8809.  
  8810. # svn completion
  8811. #
  8812. have svn &&
  8813. {
  8814. _svn()
  8815. {
  8816.     local cur prev commands options command
  8817.  
  8818.     COMPREPLY=()
  8819.     cur=${COMP_WORDS[COMP_CWORD]}
  8820.  
  8821.     commands='add blame praise annotate ann cat checkout co cleanup commit \
  8822.         ci copy cp delete del remove rm diff di export help ? h import \
  8823.         info list ls lock log merge mkdir move mv rename ren \
  8824.         propdel pdel pd propedit pedit pe propget pget pg \
  8825.         proplist plist pl propset pset ps resolved revert \
  8826.         status stat st switch sw unlock update up'
  8827.  
  8828.     if [[ $COMP_CWORD -eq 1 ]] ; then
  8829.         if [[ "$cur" == -* ]]; then
  8830.             COMPREPLY=( $( compgen -W '--version' -- $cur ) )
  8831.         else
  8832.             COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
  8833.         fi
  8834.     else
  8835.  
  8836.         prev=${COMP_WORDS[COMP_CWORD-1]}
  8837.         case $prev in
  8838.             --config-dir)
  8839.                 _filedir -d
  8840.                 return 0;
  8841.                 ;;
  8842.             -@(F|-file|-targets))
  8843.                 _filedir
  8844.                 return 0;
  8845.                 ;;
  8846.             --encoding)
  8847.                 COMPREPLY=( $( compgen -W \
  8848.                     '$( iconv --list | sed -e "s@//@@;" )' \
  8849.                     -- "$cur" ) )
  8850.                 return 0;
  8851.                 ;;
  8852.             --@(editor|diff|diff3)-cmd)
  8853.                 COMP_WORDS=(COMP_WORDS[0] $cur)
  8854.                 COMP_CWORD=1
  8855.                 _command
  8856.                 return 0;
  8857.                 ;;
  8858.         esac
  8859.  
  8860.         command=${COMP_WORDS[1]}
  8861.  
  8862.         if [[ "$cur" == -* ]]; then
  8863.             # possible options for the command
  8864.             case $command in
  8865.                 add)
  8866.                     options='--auto-props --no-auto-props \
  8867.                         --force --targets --no-ignore \
  8868.                         --non-recursive -N -q --quiet'
  8869.                     ;;
  8870.                 @(blame|annotate|ann|praise))
  8871.                     options='-r --revisions --username \
  8872.                         --password --no-auth-cache \
  8873.                         --non-interactive -v \
  8874.                         --verbose --incremental --xml'
  8875.                     ;;
  8876.                 cat)
  8877.                     options='-r --revision --username \
  8878.                         --password --no-auth-cache \
  8879.                         --non-interactive'
  8880.                     ;;
  8881.                 @(checkout|co))
  8882.                     options='-r --revision -q --quiet -N \
  8883.                         --non-recursive --username \
  8884.                         --password --no-auth-cache \
  8885.                         --non-interactive \
  8886.                         --ignore-externals'
  8887.                     ;;
  8888.                 cleanup)
  8889.                     options='--diff3-cmd'
  8890.                     ;;
  8891.                 @(commit|ci))
  8892.                     options='-m --message -F --file \
  8893.                         --encoding --force-log -q \
  8894.                         --quiet --non-recursive -N \
  8895.                         --targets --editor-cmd \
  8896.                         --username --password \
  8897.                         --no-auth-cache \
  8898.                         --non-interactive --no-unlock'
  8899.                     ;;
  8900.                 @(copy|cp))
  8901.                     options='-m --message -F --file \
  8902.                         --encoding --force-log -r \
  8903.                         --revision -q --quiet \
  8904.                         --editor-cmd -username \
  8905.                         --password --no-auth-cache \
  8906.                         --non-interactive'
  8907.                     ;;
  8908.                 @(delete|del|remove|rm))
  8909.                     options='--force -m --message -F \
  8910.                         --file --encoding --force-log \
  8911.                         -q --quiet --targets \
  8912.                         --editor-cmd -username \
  8913.                         --password --no-auth-cache \
  8914.                         --non-interactive'
  8915.                     ;;
  8916.                 @(diff|di))
  8917.                     options='-r --revision -x --extensions \
  8918.                         --diff-cmd --no-diff-deleted \
  8919.                         -N --non-recursive --username \
  8920.                         --password --no-auth-cache \
  8921.                         --non-interactive --force \
  8922.                         --old --new --notice-ancestry'
  8923.                     ;;
  8924.                 export)
  8925.                     options='-r --revision -q --quiet \
  8926.                         --username --password \
  8927.                         --no-auth-cache \
  8928.                         --non-interactive -N \
  8929.                         --non-recursive --force \
  8930.                         --native-eol --ignore-externals'
  8931.                     ;;
  8932.                 import)
  8933.                     options='--auto-props --no-auto-props \
  8934.                         -m --message -F --file \
  8935.                         --encoding --force-log -q \
  8936.                         --quiet --non-recursive \
  8937.                         --no-ignore --editor-cmd \
  8938.                         --username --password \
  8939.                         --no-auth-cache \
  8940.                         --non-interactive'
  8941.                     ;; 
  8942.                 info)
  8943.                     options='--username --password \
  8944.                         --no-auth-cache \
  8945.                         --non-interactive -r \
  8946.                         --revision --xml --targets \
  8947.                         -R --recursive --incremental'
  8948.                     ;;
  8949.                 @(list|ls))
  8950.                     options='-r --revision -v --verbose -R \
  8951.                         --recursive --username \
  8952.                         --password --no-auth-cache \
  8953.                         --non-interactive \
  8954.                         --incremental --xml'
  8955.                     ;;
  8956.                 lock)
  8957.                     options='-m --message -F --file \
  8958.                         --encoding --force-log \
  8959.                         --targets --force --username \
  8960.                         --password --no-auth-cache \
  8961.                         --non-interactive'
  8962.                     ;;
  8963.                 log)
  8964.                     options='-r --revision -v --verbose \
  8965.                         --targets --username \
  8966.                         --password --no-auth-cache \
  8967.                         --non-interactive \
  8968.                         --stop-on-copy --incremental \
  8969.                         --xml -q --quiet --limit'
  8970.                     ;;
  8971.                 merge)
  8972.                     options='-r --revision -N \
  8973.                         --non-recursive -q --quiet \
  8974.                         --force --dry-run --diff3-cmd \
  8975.                         --username --password \
  8976.                         --no-auth-cache \
  8977.                         --non-interactive \
  8978.                         --ignore-ancestry'
  8979.                     ;;
  8980.                 mkdir)
  8981.                     options='-m --message -F --file \
  8982.                         --encoding --force-log -q \
  8983.                         --quiet --editor-cmd \
  8984.                         --username --password \
  8985.                         --no-auth-cache \
  8986.                         --non-interactive'
  8987.                     ;;
  8988.                 @(move|mv|rename|ren))
  8989.                     options='-m --message -F --file \
  8990.                         --encoding --force-log -r \
  8991.                         --revision -q --quiet \
  8992.                         --force --editor-cmd \
  8993.                         --username --password \
  8994.                         --no-auth-cache \
  8995.                         --non-interactive'
  8996.                     ;;
  8997.                 @(propdel|pdel|pd))
  8998.                     options='-q --quiet -R --recursive -r \
  8999.                         --revision --revprop \
  9000.                         --username --password \
  9001.                         --no-auth-cache \
  9002.                         --non-interactive'
  9003.                     ;;
  9004.                 @(propedit|pedit|pe))
  9005.                     options='-r --revision --revprop \
  9006.                         --encoding --editor-cmd \
  9007.                         --username --password \
  9008.                         --no-auth-cache \
  9009.                         --non-interactive --force'
  9010.                     ;;
  9011.                 @(propget|pget|pg))
  9012.                     options='-R --recursive -r --revision \
  9013.                         --revprop --strict --username \
  9014.                         --password --no-auth-cache \
  9015.                         --non-interactive'
  9016.                     ;;
  9017.                 @(proplist|plist|pl))
  9018.                     options='-v --verbose -R --recursive \
  9019.                         -r --revision --revprop -q \
  9020.                         --quiet --username --password \
  9021.                         --no-auth-cache \
  9022.                         --non-interactive'
  9023.                     ;;
  9024.                 @(propset|pset|ps))
  9025.                     options='-F --file -q --quiet \
  9026.                         --targets -R --recursive \
  9027.                         --revprop --encoding \
  9028.                         --username --password \
  9029.                         --no-auth-cache \
  9030.                         --non-interactive -r \
  9031.                         --revision --force'
  9032.                     ;;
  9033.                 resolved)
  9034.                     options='--targets -R --recursive -q \
  9035.                         --quiet'
  9036.                     ;;
  9037.                 revert)
  9038.                     options='--targets -R --recursive -q \
  9039.                         --quiet'
  9040.                     ;;
  9041.                 @(status|stat|st))
  9042.                     options='-u --show-updates -v \
  9043.                         --verbose -N --non-recursive \
  9044.                         -q --quiet --username \
  9045.                         --password --no-auth-cache \
  9046.                         --non-interactive --no-ignore \
  9047.                         --ignore-externals \
  9048.                         --incremental --xml'
  9049.                     ;;
  9050.                 @(switch|sw))
  9051.                     options='--relocate -r --revision -N \
  9052.                         --non-recursive -q --quiet \
  9053.                         --username --password \
  9054.                         --no-auth-cache \
  9055.                         --non-interactive --diff3-cmd'
  9056.                     ;;
  9057.                 unlock)
  9058.                     options='--targets --force --username \
  9059.                         --password --no-auth-cache \
  9060.                         --non-interactive'
  9061.                     ;;
  9062.                 @(update|up))
  9063.                     options='-r --revision -N \
  9064.                         --non-recursive -q --quiet \
  9065.                         --username --password \
  9066.                         --no-auth-cache \
  9067.                         --non-interactive \
  9068.                         --diff3-cmd --ignore-externals'
  9069.                     ;;
  9070.             esac
  9071.             options="$options --help -h --config-dir"
  9072.  
  9073.             COMPREPLY=( $( compgen -W "$options" -- $cur ) )
  9074.         else
  9075.             if [[ "$command" == @(help|h|\?) ]]; then
  9076.                 COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
  9077.             else
  9078.                 _filedir
  9079.             fi
  9080.         fi
  9081.     fi
  9082.  
  9083.     return 0
  9084. }
  9085. complete -F _svn $default svn
  9086.  
  9087. _svnadmin()
  9088. {
  9089.     local cur prev commands options mode
  9090.  
  9091.     COMPREPLY=()
  9092.     cur=${COMP_WORDS[COMP_CWORD]}
  9093.  
  9094.     commands='create deltify dump help ? hotcopy list-dblogs \
  9095.         list-unused-dblogs load lslocks lstxns recover rmlocks \
  9096.         rmtxns setlog verify'
  9097.  
  9098.     if [[ $COMP_CWORD -eq 1 ]] ; then
  9099.         if [[ "$cur" == -* ]]; then
  9100.             COMPREPLY=( $( compgen -W '--version' -- $cur ) )
  9101.         else
  9102.             COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
  9103.         fi
  9104.     else
  9105.         prev=${COMP_WORDS[COMP_CWORD-1]}
  9106.         case $prev in
  9107.             --config-dir)
  9108.                 _filedir -d
  9109.                 return 0;
  9110.                 ;;
  9111.             --fs-type)
  9112.                 COMPREPLY=( $( compgen -W 'fsfs bdb' -- $cur ) )
  9113.                 return 0;
  9114.                 ;;
  9115.         esac
  9116.  
  9117.         command=${COMP_WORDS[1]}
  9118.  
  9119.         if [[ "$cur" == -* ]]; then
  9120.             # possible options for the command
  9121.             case $command in
  9122.                 create)
  9123.                     options='--bdb-txn-nosync \
  9124.                         --bdb-log-keep --config-dir \
  9125.                         --fs-type'
  9126.                     ;;
  9127.                 deltify)
  9128.                     options='-r --revision -q --quiet'
  9129.                     ;;
  9130.                 dump)
  9131.                     options='-r --revision --incremental \
  9132.                         -q --quiet --deltas'
  9133.                     ;;
  9134.                 hotcopy)
  9135.                     options='--clean-logs'
  9136.                     ;;
  9137.                 load)
  9138.                     options='--ignore-uuid --force-uuid \
  9139.                         --parent-dir -q --quiet \
  9140.                         --use-pre-commit-hook \
  9141.                         --use-post-commit-hook'
  9142.                     ;;
  9143.                 rmtxns)
  9144.                     options='-q --quiet'
  9145.                     ;;
  9146.                 setlog)
  9147.                     options='-r --revision --bypass-hooks'
  9148.                     ;;
  9149.             esac
  9150.  
  9151.             options="$options --help -h"
  9152.             COMPREPLY=( $( compgen -W "$options" -- $cur ) )
  9153.         else
  9154.             if [[ "$command" == @(help|h|\?) ]]; then
  9155.                 COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
  9156.             else
  9157.                 _filedir
  9158.             fi
  9159.         fi
  9160.     fi
  9161.  
  9162.     return 0
  9163. }
  9164. complete -F _svnadmin $default svnadmin
  9165.  
  9166. _svnlook()
  9167. {
  9168.     local cur prev commands options mode
  9169.  
  9170.     COMPREPLY=()
  9171.     cur=${COMP_WORDS[COMP_CWORD]}
  9172.  
  9173.     commands='author cat changed date diff dirs-changed help ? h history \
  9174.         info lock log propget pget pg proplist plist pl tree uuid \
  9175.         youngest'
  9176.  
  9177.     if [[ $COMP_CWORD -eq 1 ]] ; then
  9178.         if [[ "$cur" == -* ]]; then
  9179.             COMPREPLY=( $( compgen -W '--version' -- $cur ) )
  9180.         else
  9181.             COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
  9182.         fi
  9183.     else
  9184.         command=${COMP_WORDS[1]}
  9185.  
  9186.         if [[ "$cur" == -* ]]; then
  9187.             # possible options for the command
  9188.             case $command in
  9189.                 @(author|cat|date|dirs-changed|info|log))
  9190.                     options='-r --revision -t \
  9191.                         --transaction'
  9192.                     ;;
  9193.                 changed)
  9194.                     options='-r --revision -t \
  9195.                         --transaction --copy-info'
  9196.                     ;;
  9197.                 diff)
  9198.                     options='-r --revision -t \
  9199.                         --transaction \
  9200.                         --no-diff-deleted \
  9201.                         --no-diff-added \
  9202.                         --diff-copy-from'
  9203.                     ;;
  9204.                 history)
  9205.                     options='-r --revision --show-ids'
  9206.                     ;;
  9207.                 prop@(get|list))
  9208.                     options='-r --revision -t \
  9209.                         --transaction --revprop'
  9210.                     ;;
  9211.                 tree)
  9212.                     options='-r --revision -t \
  9213.                         --transaction --show-ids \
  9214.                         --full-paths'
  9215.                     ;;
  9216.             esac
  9217.  
  9218.             options="$options --help -h"
  9219.             COMPREPLY=( $( compgen -W "$options" -- $cur ) )
  9220.         else
  9221.             if [[ "$command" == @(help|h|\?) ]]; then
  9222.                 COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
  9223.             else
  9224.                 _filedir
  9225.             fi
  9226.         fi
  9227.     fi
  9228.  
  9229.     return 0
  9230. }
  9231. complete -F _svnlook $default svnlook
  9232. }
  9233.  
  9234. _filedir_xspec()
  9235. {
  9236.     local IFS cur xspec
  9237.  
  9238.     IFS=$'\t\n'
  9239.     COMPREPLY=()
  9240.     cur=${COMP_WORDS[COMP_CWORD]}
  9241.  
  9242.     _expand || return 0
  9243.  
  9244.     # get first exclusion compspec that matches this command
  9245.     xspec=$( sed -ne $'/^complete .*[ \t]'${1##*/}$'\([ \t]\|$\)/{p;q;}' \
  9246.           $BASH_COMPLETION )
  9247.     # prune to leave nothing but the -X spec
  9248.     xspec=${xspec#*-X }
  9249.     xspec=${xspec%% *}
  9250.  
  9251.     COMPREPLY=( $( eval compgen -f -X "$xspec" -- \
  9252.             \"${cur#[\`\"\']}\" 2>/dev/null ) \
  9253.             $( compgen -d -- $cur ) )
  9254. }
  9255. list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' \
  9256.       $BASH_COMPLETION | \
  9257.     # read exclusion compspecs
  9258.     (
  9259.     while read line
  9260.     do
  9261.         # ignore compspecs that are commented out
  9262.         if [ "${line#\#}" != "$line" ]; then continue; fi
  9263.         line=${line%# START exclude*}
  9264.         line=${line%# FINISH exclude*}
  9265.         line=${line##*\'}
  9266.         list=( ${list[@]:-} $line )
  9267.     done
  9268.     echo ${list[@]}
  9269.     )
  9270.      ) )
  9271. # remove previous compspecs
  9272. if [ ${#list[@]} -gt 0 ]; then
  9273.     eval complete -r ${list[@]}
  9274.     # install new compspecs
  9275.     eval complete -F _filedir_xspec $filenames ${list[@]}
  9276. fi
  9277. unset list
  9278.  
  9279. # source completion directory definitions
  9280. if [ -d $BASH_COMPLETION_DIR -a -r $BASH_COMPLETION_DIR -a \
  9281.      -x $BASH_COMPLETION_DIR ]; then
  9282.     for i in $BASH_COMPLETION_DIR/*; do
  9283.         [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|.rpm*) ]] &&
  9284.             [ \( -f $i -o -h $i \) -a -r $i ] && . $i
  9285.     done
  9286. fi
  9287. unset i
  9288.  
  9289. # source user completion file
  9290. [ $BASH_COMPLETION != ~/.bash_completion -a -r ~/.bash_completion ] \
  9291.     && . ~/.bash_completion
  9292. unset -f have
  9293. unset UNAME RELEASE default dirnames filenames have nospace bashdefault \
  9294.       plusdirs
  9295.  
  9296. ###  Local Variables:
  9297. ###  mode: shell-script
  9298. ###  End:
  9299.