From 9b20f822d01a0c33e6321deb42d6d59e818d6c5a Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Thu, 26 Aug 1999 10:07:28 +0000 Subject: zsh-workers/7492 --- Completion/Base/_arguments | 203 +++++++++++++++++++++++++-------------------- Completion/User/_find | 86 ++++++++++++------- Completion/X/_x_font | 2 +- 3 files changed, 172 insertions(+), 119 deletions(-) (limited to 'Completion') diff --git a/Completion/Base/_arguments b/Completion/Base/_arguments index 2a2eb1b25..bb55a1881 100644 --- a/Completion/Base/_arguments +++ b/Completion/Base/_arguments @@ -14,120 +14,145 @@ local beg optbeg argbeg nargbeg inopt typeset -A opts dopts odopts typeset -A oneshot -# See if we are using single-letter options. +# Fill the cache if we were called with different arguments. -if [[ "$1" = -s ]]; then - shift - single=yes -fi +if [[ "$*" != "$_args_cache_descr" ]]; then + _args_cache_descr="$*" -# See if we support long options, too. + unset _args_cache_{opts,dopts,odopts,oneshot} + typeset -gA _args_cache_{opts,dopts,odopts,oneshot} -nth=$argv[(I)--] -if (( nth )); then - long=( "${(@)argv[nth+1,-1]}" ) - argv=("${(@)argv[1,nth-1]}") -else - long=() -fi + unset _args_cache_{long,single,rest,args,sopts,soptseq,soptseq1} -# Now parse the arguments... + # See if we are using single-letter options. -args=() -nth=1 -while (( $# )); do + if [[ "$1" = -s ]]; then + shift + _args_cache_single=yes + fi + + # See if we support long options, too. + + nth=$argv[(I)--] + if (( nth )); then + _args_cache_long=( "${(@)argv[nth+1,-1]}" ) + _args_cache_long_nth=$(( nth - 1 )) + else + _args_cache_long=() + fi + + # Now parse the arguments... - # This describes a one-shot option. + args=() + nth=1 + while (( $# )); do - if [[ "$1" = [-+]* ]]; then - if [[ "$1" = *:* ]]; then + # This describes a one-shot option. - # If the option name ends in a `-', the first argument comes - # directly after the option, if it ends in a `+', the first - # argument *may* come directly after the option, otherwise it - # is in the next word. + if [[ "$1" = [-+]* ]]; then + if [[ "$1" = *:* ]]; then - if [[ "$1" = [^:]##-:* ]]; then - tmp="${${1%%:*}[1,-2]}" - dopts[$tmp]="${1#*:}" - elif [[ "$1" = [^:]##+:* ]]; then - tmp="${${1%%:*}[1,-2]}" - odopts[$tmp]="${1#*:}" + # If the option name ends in a `-', the first argument comes + # directly after the option, if it ends in a `+', the first + # argument *may* come directly after the option, otherwise it + # is in the next word. + + if [[ "$1" = [^:]##-:* ]]; then + tmp="${${1%%:*}[1,-2]}" + _args_cache_dopts[$tmp]="${1#*:}" + elif [[ "$1" = [^:]##+:* ]]; then + tmp="${${1%%:*}[1,-2]}" + _args_cache_odopts[$tmp]="${1#*:}" + else + tmp="${1%%:*}" + _args_cache_opts[$tmp]="${1#*:}" + fi else - tmp="${1%%:*}" - opts[$tmp]="${1#*:}" + tmp="$1" + _args_cache_opts[$tmp]='' fi - else - tmp="$1" - opts[$tmp]='' - fi - oneshot[$tmp]=yes - elif [[ "$1" = \*[-+]* ]]; then - - # The same for options that may appear more than once. - - if [[ "$1" = *:* ]]; then - if [[ "$1" = [^:]##-:* ]]; then - tmp="${${1[2,-1]%%:*}[1,-2]}" - dopts[$tmp]="${1#*:}" - elif [[ "$1" = [^:]##+:* ]]; then - tmp="${${1[2,-1]%%:*}[1,-2]}" - odopts[$tmp]="${1#*:}" + _args_cache_oneshot[$tmp]=yes + elif [[ "$1" = \*[-+]* ]]; then + + # The same for options that may appear more than once. + + if [[ "$1" = *:* ]]; then + if [[ "$1" = [^:]##-:* ]]; then + tmp="${${1[2,-1]%%:*}[1,-2]}" + _args_cache_dopts[$tmp]="${1#*:}" + elif [[ "$1" = [^:]##+:* ]]; then + tmp="${${1[2,-1]%%:*}[1,-2]}" + _args_cache_odopts[$tmp]="${1#*:}" + else + tmp="${1[2,-1]%%:*}" + _args_cache_opts[$tmp]="${1#*:}" + fi else - tmp="${1[2,-1]%%:*}" - opts[$tmp]="${1#*:}" + tmp="${1[2,-1]}" + _args_cache_opts[$tmp]='' fi - else - tmp="${1[2,-1]}" - opts[$tmp]='' - fi - unset "oneshot[$tmp]" - elif [[ "$1" = \*::* ]]; then + unset "_args_cache_oneshot[$tmp]" + elif [[ "$1" = \*::* ]]; then - # This is `*:...', describing `all other arguments', with argument - # range restriction. + # This is `*:...', describing `all other arguments', with argument + # range restriction. - if [[ "$1" = \*:::* ]]; then - rest="*${1[3,-1]}" - else - rest="$1" - fi - elif [[ "$1" = \*:* ]]; then + if [[ "$1" = \*:::* ]]; then + _args_cache_rest="*${1[3,-1]}" + else + _args_cache_rest="$1" + fi + elif [[ "$1" = \*:* ]]; then - # This is `*:...', describing `all other arguments'. + # This is `*:...', describing `all other arguments'. - rest="${1[3,-1]}" - elif [[ "$1" = :* ]]; then + _args_cache_rest="${1[3,-1]}" + elif [[ "$1" = :* ]]; then - # This is `:...', describing `the next argument'. + # This is `:...', describing `the next argument'. - args[nth++]="${1#*:}" - else + _args_cache_args[nth++]="${1#*:}" + else - # And this is `n:...', describing the `n'th argument. + # And this is `n:...', describing the `n'th argument. - args[${1%%:*}]="${1#*:}" - nth=$(( ${1%%:*} + 1 )) - fi - shift -done - -if [[ -n "$single" ]]; then - soptseq="${(@j::)${(@M)${(@k)opts[(R)]}:#[-+]?}#[-+]}" - if [[ -n "$soptseq" ]]; then - soptseq="[$soptseq]#" - soptseq1="$soptseq#" + _args_cache_args[${1%%:*}]="${1#*:}" + nth=$(( ${1%%:*} + 1 )) + fi + shift + done + + if [[ -n "$_args_cache_single" ]]; then + _args_cache_soptseq="${(@j::)${(@M)${(@k)opts[(R)]}:#[-+]?}#[-+]}" + if [[ -n "$_args_cache_soptseq" ]]; then + _args_cache_soptseq="[$_args_cache_soptseq]#" + _args_cache_soptseq1="$_args_cache_soptseq#" + else + _args_cache_soptseq='' + _args_cache_soptseq1='' + fi + _args_cache_sopts="${(@j::)${(@M)${(@k)opts}:#[-+]?}#[-+]}${(@j::)${(@M)${(@k)dopts}:#[-+]?}#[-+]}${(@j::)${(@M)${(@k)odopts}:#[-+]?}#[-+]}" else - soptseq='' - soptseq1='' + _args_cache_soptseq='' + _args_cache_soptseq1='' + _args_cache_sopts='' fi - sopts="${(@j::)${(@M)${(@k)opts}:#[-+]?}#[-+]}${(@j::)${(@M)${(@k)dopts}:#[-+]?}#[-+]}${(@j::)${(@M)${(@k)odopts}:#[-+]?}#[-+]}" -else - soptseq='' - soptseq1='' - sopts='' fi +soptseq="$_args_cache_soptseq" +soptseq1="$_args_cache_soptseq1" +sopts="$_args_cache_sopts" +args=( "$_args_cache_args[@]" ) +rest="$_args_cache_rest" +opts=( "${(@kv)_args_cache_opts}" ) +dopts=( "${(@kv)_args_cache_dopts}" ) +odopts=( "${(@kv)_args_cache_odopts}" ) +oneshot=( "${(@kv)_args_cache_oneshot}" ) +single="$_args_cache_single" +long=( "$_args_cache_long[@]" ) + +argv=( "${(@)argv[1,_args_cache_long_nth]}" ) + # Parse the command line... ws=( "${(@)words[2,-1]}" ) diff --git a/Completion/User/_find b/Completion/User/_find index 3ccb14c32..4f918e450 100644 --- a/Completion/User/_find +++ b/Completion/User/_find @@ -1,31 +1,59 @@ #compdef find -local prev="$words[CURRENT-1]" expl - -if compset -N '-(ok|exec)' '\;'; then - _normal -elif [[ "$PREFIX" = -* ]]; then - _description expl option - compadd "$expl[@]" - -daystart -{max,min,}depth -follow -noleaf \ - -version -xdev -{a,c,}newer -{a,c,m}{min,time} -empty -false \ - -{fs,x,}type -gid -inum -links -{i,}{l,}name -{no,}{user,group} \ - -path -perm -regex -size -true -uid -used -exec -{f,}print{f,0,} \ - -ok -prune -ls -elif [[ CURRENT -eq 2 ]]; then - local ret=1 - - _description expl directory - compgen "$expl[@]" -g '. ..' && ret=0 - _files -/ && ret=0 - - return ret -elif [[ "$prev" = -((a|c|)newer|fprint(|0|f)) ]]; then - _files -elif [[ "$prev" = -fstype ]]; then - _description expl 'file system type' - compadd "$expl[@]" ufs 4.2 4.3 nfs tmp mfs S51K S52K -elif [[ "$prev" = -group ]]; then - _groups -elif [[ "$prev" = -user ]]; then - _users -fi +_arguments \ + '-daystart' \ + '-depth' \ + '-follow' \ + '-help' \ + '-maxdepth:maximum search depth:' \ + '-mindepth:minimum search depth:' \ + '-mount' \ + '-noleaf' \ + '-version' \ + '-xdev' \ + '-amin:access time (minutes):' \ + '-cmin:inode change time (minutes):' \ + '-mmin:modification time (minutes):' \ + '-atime:access time (days):' \ + '-ctime:inode change time (days):' \ + '-mtime:modification time (days):' \ + '-anewer:file to compare (access time):_files' \ + '-cnewer:file to compare (inode change time):_files' \ + '-newer:file to compare (modification time):_files' \ + '-used:access after inode change (days):' \ + '-empty' \ + '-false' \ + '-fstype:filesystem type:(ufs 4.2 4.3 nfs tmp mfs S51K S52K)' \ + '-gid:numeric group ID:' \ + '-group:group:_groups' \ + '-uid:numeric user ID:' \ + '-user:user:_users' \ + '-lname:link pattern to search:' \ + '-ilname:link pattern to search (case insensitive):' \ + '-name:name pattern to search:' \ + '-iname:name pattern to search (case insensitive):' \ + '-path:path pattern to search:' \ + '-ipath:path pattern to search (case insensitive):' \ + '-regex:regular expression to search:' \ + '-iregex:regular expression to search (case insensitive):' \ + '-inum:inode number:' \ + '-links:number of links:' \ + '-nouser' \ + '-nogroup' \ + '-perm:file permission bits:' \ + '-size:file size:' \ + '-true' \ + '-type:file type:(b c d p f l s)' \ + '-xtype:file type:(b c d p f l s)' \ + '-exec:program: _command_names -e:*\;::program arguments: _normal' \ + '-ok:program: _command_names -e:*\;::program arguments: _normal' \ + '-fls:output file:_files' \ + '-fprint:output file:_files' \ + '-fprint0:output file:_files' \ + '-fprintf:output file:_files:output format:' \ + '-print' \ + '-print0' \ + '-printf:output format:' \ + '-prune' \ + '-ls' \ + '*:directory:_files -/' diff --git a/Completion/X/_x_font b/Completion/X/_x_font index d4f16f33c..f0b13c7a8 100644 --- a/Completion/X/_x_font +++ b/Completion/X/_x_font @@ -5,7 +5,7 @@ local expl # This *has* to be improved some day... if (( ! $+_font_cache )); then - typeset -U _font_cache + typeset -gU _font_cache _font_cache=( "${(@)^${(@f)$(xlsfonts)}%%--*}--" ) fi -- cgit 1.4.1