home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / bash_completion.d / findutils < prev    next >
Encoding:
Text File  |  2010-11-16  |  4.2 KB  |  129 lines

  1. # bash completion for GNU find. This makes heavy use of ksh style extended
  2. # globs and contains Linux specific code for completing the parameter
  3. # to the -fstype option.
  4.  
  5. have find &&
  6. _find()
  7. {
  8.     local cur prev i exprfound onlyonce
  9.  
  10.     COMPREPLY=()
  11.     _get_comp_words_by_ref cur prev
  12.  
  13.     case $prev in
  14.         -maxdepth|-mindepth)
  15.             COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9' -- "$cur" ) )
  16.             return 0
  17.             ;;
  18.         -newer|-anewer|-cnewer|-fls|-fprint|-fprint0|-fprintf|-name|-iname|\
  19.         -lname|-ilname|-wholename|-iwholename|-samefile)
  20.             _filedir
  21.             return 0
  22.             ;;
  23.         -fstype)
  24.             _fstypes
  25.             if [[ "$( uname -s )" == *BSD ]] ; then
  26.                 COMPREPLY=( "${COMPREPLY[@]}" \
  27.                     $( compgen -W 'local rdonly' -- "$cur" ) )
  28.             fi
  29.             return 0
  30.             ;;
  31.         -gid)
  32.             _gids
  33.             return 0
  34.             ;;
  35.         -group)
  36.             COMPREPLY=( $( compgen -g -- "$cur" 2>/dev/null) )
  37.             return 0
  38.             ;;
  39.         -xtype|-type)
  40.             COMPREPLY=( $( compgen -W 'b c d p f l s' -- "$cur" ) )
  41.             return 0
  42.             ;;
  43.         -uid)
  44.             _uids
  45.             return 0
  46.             ;;
  47.         -user)
  48.             COMPREPLY=( $( compgen -u -- "$cur" ) )
  49.             return 0
  50.             ;;
  51.         -exec|-execdir|-ok|-okdir)
  52.             COMP_WORDS=(COMP_WORDS[0] "$cur")
  53.             COMP_CWORD=1
  54.             _command
  55.             return 0
  56.             ;;
  57.         -[acm]min|-[acm]time|-iname|-lname|-wholename|-iwholename|-lwholename|\
  58.         -ilwholename|-inum|-path|-ipath|-regex|-iregex|-links|-perm|-size|\
  59.         -used|-printf|-context)
  60.             # do nothing, just wait for a parameter to be given
  61.             return 0
  62.             ;;
  63.         -regextype)
  64.             COMPREPLY=( $( compgen -W 'emacs posix-awk posix-basic \
  65.                 posix-egrep posix-extended' -- "$cur" ) )
  66.             return 0
  67.             ;;
  68.     esac
  69.  
  70.     _expand || return 0
  71.     # set exprfound to 1 if there is already an expression present
  72.     for i in ${COMP_WORDS[@]}; do
  73.         [[ "$i" = [-\(\),\!]* ]] && exprfound=1 && break
  74.     done
  75.  
  76.     # handle case where first parameter is not a dash option
  77.     if [[ "$exprfound" != 1 && "$cur" != [-\(\),\!]* ]]; then
  78.         _filedir -d
  79.         return 0
  80.     fi
  81.  
  82.     # complete using basic options
  83.     COMPREPLY=( $( compgen -W '-daystart -depth -follow -help \
  84.         -ignore_readdir_race -maxdepth -mindepth -mindepth -mount \
  85.         -noignore_readdir_race -noleaf -regextype -version -warn -nowarn \
  86.         -xdev \
  87.         -amin -anewer -atime -cmin -cnewer -ctime -empty -executable -false \
  88.         -fstype -gid -group -ilname -iname -inum -ipath -iregex -iwholename \
  89.         -links -lname -mmin -mtime -name -newer -nogroup -nouser -path -perm \
  90.         -readable -regex -samefile -size -true -type -uid -used -user \
  91.         -wholename -writable -xtype -context \
  92.         -delete -exec -execdir -fls -fprint -fprint0 -fprintf -ls -ok -okdir \
  93.         -print -print0 -printf -prune -quit' -- "$cur" ) )
  94.  
  95.     # this removes any options from the list of completions that have
  96.     # already been specified somewhere on the command line, as long as
  97.     # these options can only be used once (in a word, "options", in
  98.     # opposition to "tests" and "actions", as in the find(1) manpage).
  99.     onlyonce=' -daystart -depth -follow -help -ignore_readdir_race -maxdepth \
  100.        -mindepth -mount -noignore_readdir_race -noleaf -nowarn -regextype \
  101.        -version -warn -xdev '
  102.     COMPREPLY=( $( \
  103.            (while read -d ' ' i; do
  104.             [[ -z "$i" || "${onlyonce/ ${i%% *} / }" == "$onlyonce" ]] &&
  105.             continue
  106.             # flatten array with spaces on either side,
  107.             # otherwise we cannot grep on word boundaries of
  108.             # first and last word
  109.             COMPREPLY=" ${COMPREPLY[@]} "
  110.             # remove word from list of completions
  111.             COMPREPLY=( ${COMPREPLY/ ${i%% *} / } )
  112.             done
  113.             printf '%s ' "${COMPREPLY[@]}") <<<"${COMP_WORDS[@]}"
  114.           ) )
  115.  
  116.     _filedir
  117.  
  118.     return 0
  119. } &&
  120. complete -F _find -o filenames find
  121.  
  122. # Local variables:
  123. # mode: shell-script
  124. # sh-basic-offset: 4
  125. # sh-indent-comment: t
  126. # indent-tabs-mode: nil
  127. # End:
  128. # ex: ts=4 sw=4 et filetype=sh
  129.