# bash completion for GNU find -*- shell-script -*- # This makes heavy use of ksh style extended globs and contains Linux specific # code for completing the parameter to the -fstype option. proc _find { local cur prev words cword _init_completion || return match $prev { with -maxdepth|-mindepth setglobal COMPREPLY = ''( $( compgen -W '{0..9}' -- "$cur" ) ) return 0 with -newer|-anewer|-cnewer|-fls|-fprint|-fprint0|-fprintf|-name|-iname|\ -lname|-ilname|-wholename|-iwholename|-samefile _filedir return 0 with -fstype _fstypes [[ $OSTYPE == *bsd* ]] && \ setglobal COMPREPLY = ''( $( compgen -W 'local rdonly' -- "$cur" ) ) return 0 with -gid _gids return 0 with -group setglobal COMPREPLY = ''( $( compgen -g -- "$cur" 2>/dev/null) ) return 0 with -xtype|-type setglobal COMPREPLY = ''( $( compgen -W 'b c d p f l s' -- "$cur" ) ) return 0 with -uid _uids return 0 with -user setglobal COMPREPLY = ''( $( compgen -u -- "$cur" ) ) return 0 with -exec|-execdir|-ok|-okdir setglobal words = ''(words[0] "$cur") setglobal cword = '1' _command return 0 with -[acm]min|-[acm]time|-iname|-lname|-wholename|-iwholename|-lwholename|\ -ilwholename|-inum|-path|-ipath|-regex|-iregex|-links|-perm|-size|\ -used|-printf|-context # do nothing, just wait for a parameter to be given return 0 with -regextype setglobal COMPREPLY = ''( $( compgen -W 'emacs posix-awk posix-basic posix-egrep posix-extended' -- "$cur" ) ) return 0 } _expand || return 0 local i exprfound=false # set exprfound to true if there is already an expression present for i in [$(words[@])] { [[ "$i" == [-\(\),\!]* ]] && setglobal exprfound = 'true' && break } # handle case where first parameter is not a dash option if ! $exprfound && [[ "$cur" != [-\(\),\!]* ]] { _filedir -d return 0 } # complete using basic options setglobal COMPREPLY = ''( $( compgen -W '-daystart -depth -follow -help -ignore_readdir_race -maxdepth -mindepth -mindepth -mount -noignore_readdir_race -noleaf -regextype -version -warn -nowarn -xdev -amin -anewer -atime -cmin -cnewer -ctime -empty -executable -false -fstype -gid -group -ilname -iname -inum -ipath -iregex -iwholename -links -lname -mmin -mtime -name -newer -nogroup -nouser -path -perm -readable -regex -samefile -size -true -type -uid -used -user -wholename -writable -xtype -context -delete -exec -execdir -fls -fprint -fprint0 -fprintf -ls -ok -okdir -print -print0 -printf -prune -quit' -- "$cur" ) ) if [[ ${#COMPREPLY[@]} -ne 0 ]] { # this removes any options from the list of completions that have # already been specified somewhere on the command line, as long as # these options can only be used once (in a word, "options", in # opposition to "tests" and "actions", as in the find(1) manpage). local -A onlyonce=( [-daystart]=1 [-depth]=1 [-follow]=1 [-help]=1 [-ignore_readdir_race]=1 [-maxdepth]=1 [-mindepth]=1 [-mount]=1 [-noignore_readdir_race]=1 [-noleaf]=1 [-nowarn]=1 [-regextype]=1 [-version]=1 [-warn]=1 [-xdev]=1 ) local j for i in [$(words[@])] { [[ $i && ${onlyonce[$i]} ]] || continue for j in [$(!COMPREPLY[@])] { [[ ${COMPREPLY[j]} == $i ]] && unset 'COMPREPLY[j]' } } } _filedir return 0 } && complete -F _find find # ex: ts=4 sw=4 et filetype=sh