summaryrefslogtreecommitdiff
path: root/completions/find
diff options
context:
space:
mode:
Diffstat (limited to 'completions/find')
-rw-r--r--completions/find63
1 files changed, 32 insertions, 31 deletions
diff --git a/completions/find b/completions/find
index 80fbe8c0..64121eda 100644
--- a/completions/find
+++ b/completions/find
@@ -7,20 +7,28 @@ _find()
local cur prev words cword
_init_completion || return
+ local i
+ for i in ${!words[*]}; do
+ if [[ ${words[i]} == -@(exec|ok)?(dir) ]]; then
+ _command_offset $((i + 1))
+ return
+ fi
+ done
+
case $prev in
- -maxdepth|-mindepth)
- COMPREPLY=( $(compgen -W '{0..9}' -- "$cur") )
+ -maxdepth | -mindepth)
+ COMPREPLY=($(compgen -W '{0..9}' -- "$cur"))
return
;;
- -newer|-anewer|-cnewer|-fls|-fprint|-fprint0|-fprintf|-name|-iname|\
- -lname|-ilname|-wholename|-iwholename|-samefile)
+ -newer | -anewer | -cnewer | -fls | -fprint | -fprint0 | -fprintf | -name | -[il]name | \
+ -ilname | -wholename | -[il]wholename | -samefile)
_filedir
return
;;
-fstype)
_fstypes
- [[ $OSTYPE == *bsd* ]] && \
- COMPREPLY+=( $(compgen -W 'local rdonly' -- "$cur") )
+ [[ $OSTYPE == *bsd* ]] &&
+ COMPREPLY+=($(compgen -W 'local rdonly' -- "$cur"))
return
;;
-gid)
@@ -28,11 +36,11 @@ _find()
return
;;
-group)
- COMPREPLY=( $(compgen -g -- "$cur" 2>/dev/null) )
+ COMPREPLY=($(compgen -g -- "$cur" 2>/dev/null))
return
;;
- -xtype|-type)
- COMPREPLY=( $(compgen -W 'b c d p f l s' -- "$cur") )
+ -xtype | -type)
+ COMPREPLY=($(compgen -W 'b c d p f l s' -- "$cur"))
return
;;
-uid)
@@ -40,24 +48,17 @@ _find()
return
;;
-user)
- COMPREPLY=( $(compgen -u -- "$cur") )
- return
- ;;
- -exec|-execdir|-ok|-okdir)
- words=(words[0] "$cur")
- cword=1
- _command
+ COMPREPLY=($(compgen -u -- "$cur"))
return
;;
- -[acm]min|-[acm]time|-iname|-lname|-wholename|-iwholename|-lwholename|\
- -ilwholename|-inum|-path|-ipath|-regex|-iregex|-links|-perm|-size|\
- -used|-printf|-context)
+ -[acm]min | -[acm]time | -inum | -path | -ipath | -regex | -iregex | -links | -perm | \
+ -size | -used | -printf | -context)
# do nothing, just wait for a parameter to be given
return
;;
-regextype)
- COMPREPLY=( $(compgen -W 'emacs posix-awk posix-basic posix-egrep
- posix-extended' -- "$cur") )
+ COMPREPLY=($(compgen -W 'emacs posix-awk posix-basic posix-egrep
+ posix-extended' -- "$cur"))
return
;;
esac
@@ -65,17 +66,17 @@ _find()
local i exprfound=false
# set exprfound to true if there is already an expression present
for i in "${words[@]}"; do
- [[ "$i" == [-\(\),\!]* ]] && exprfound=true && break
+ [[ $i == [-\(\),\!]* ]] && exprfound=true && break
done
# handle case where first parameter is not a dash option
- if ! $exprfound && [[ "$cur" != [-\(\),\!]* ]]; then
+ if ! $exprfound && [[ $cur != [-\(\),\!]* ]]; then
_filedir -d
return
fi
# complete using basic options
- COMPREPLY=( $(compgen -W '-daystart -depth -follow -help
+ 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
@@ -84,22 +85,22 @@ _find()
-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") )
+ -quit' -- "$cur"))
- if [[ ${#COMPREPLY[@]} -ne 0 ]]; then
+ if ((${#COMPREPLY[@]} != 0)); then
# 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
+ 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 )
+ [-version]=1 [-warn]=1 [-xdev]=1)
local j
for i in "${words[@]}"; do
- [[ $i && ${onlyonce[$i]} ]] || continue
+ [[ $i && -v onlyonce["$i"] ]] || continue
for j in "${!COMPREPLY[@]}"; do
- [[ ${COMPREPLY[j]} == $i ]] && unset 'COMPREPLY[j]'
+ [[ ${COMPREPLY[j]} == "$i" ]] && unset 'COMPREPLY[j]'
done
done
fi
@@ -107,6 +108,6 @@ _find()
_filedir
} &&
-complete -F _find find
+ complete -F _find find
# ex: filetype=sh