about summary refs log tree commit diff
path: root/Completion/Base
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-11-12 15:28:24 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-11-12 15:28:24 +0000
commite6282df1155e8d9b08b2e518a452c1997973f1ce (patch)
treeb0c8ed7e8512cc4397ae7df6d138ea66147565b3 /Completion/Base
parent167b0ae3b98938f75287dcf2e112d41a03532c5f (diff)
downloadzsh-e6282df1155e8d9b08b2e518a452c1997973f1ce.tar.gz
zsh-e6282df1155e8d9b08b2e518a452c1997973f1ce.tar.xz
zsh-e6282df1155e8d9b08b2e518a452c1997973f1ce.zip
manual/8630
Diffstat (limited to 'Completion/Base')
-rw-r--r--Completion/Base/_arguments41
-rw-r--r--Completion/Base/_brace_parameter2
-rw-r--r--Completion/Base/_command_names45
-rw-r--r--Completion/Base/_condition11
-rw-r--r--Completion/Base/_default7
-rw-r--r--Completion/Base/_describe12
-rw-r--r--Completion/Base/_equal11
-rw-r--r--Completion/Base/_jobs18
-rw-r--r--Completion/Base/_math2
-rw-r--r--Completion/Base/_parameter2
-rw-r--r--Completion/Base/_subscript49
-rw-r--r--Completion/Base/_tilde69
-rw-r--r--Completion/Base/_values35
-rw-r--r--Completion/Base/_vars10
14 files changed, 192 insertions, 122 deletions
diff --git a/Completion/Base/_arguments b/Completion/Base/_arguments
index 68b52eef4..fbc7d7875 100644
--- a/Completion/Base/_arguments
+++ b/Completion/Base/_arguments
@@ -3,7 +3,7 @@
 # Complete the arguments of the current command according to the
 # descriptions given as arguments to this function.
 
-local long cmd="$words[1]" descr mesg
+local long cmd="$words[1]" descr mesg subopts
 
 long=$argv[(I)--]
 if (( long )); then
@@ -151,17 +151,30 @@ if (( long )); then
   set -- "$tmpargv[@]" "${(@P)name}"
 fi
 
+if [[ "$1" = -O?* ]]; then
+  subopts=( "${(@P)1[3,-1]}" )
+  shift
+elif [[ "$1" = -O ]]; then
+  subopts=( "${(@P)1}" )
+  shift 2
+else
+  subopts=()
+fi
+
 if comparguments -i "$compconfig[autodescribe_options]" "$@"; then
   local nm="$compstate[nmatches]" action noargs aret expl local
   local next direct odirect equal single match matched ws tmp1 tmp2
-  local opts
+  local opts _sub_context oldsc="${_sub_context}"
 
   if comparguments -D descr action; then
+    comparguments -C _sub_context
+    _sub_context="${oldsc}:${oldsc:+${oldsc}-}${_sub_context}"
+
     if comparguments -O next direct odirect equal; then
       opts=yes
-      _tags argument option
+      _tags "${oldsc}:any" arguments options
     else
-      _tags argument
+      _tags "${oldsc}:any" arguments
     fi
   else
     if comparguments -a; then
@@ -172,12 +185,12 @@ if comparguments -i "$compconfig[autodescribe_options]" "$@"; then
     comparguments -O next direct odirect equal || return 1
 
     opts=yes
-    _tags option
+    _tags "${oldsc}:any" options
   fi
 
   while _tags; do
     while true; do
-      if [[ -n "$matched" ]] || _requested argument; then
+      if [[ -n "$matched" ]] || _requested arguments; then
         _description expl "$descr"
 
         if [[ "$action" = -\>* ]]; then
@@ -207,13 +220,13 @@ if comparguments -i "$compconfig[autodescribe_options]" "$@"; then
 
             eval ws\=\( "${action[3,-3]}" \)
 
-            _describe -c "$cmd" "$descr" ws -M "$match"
+            _describe -c "$cmd" "$descr" ws -M "$match" "$subopts[@]"
 
           elif [[ "$action" = \(*\) ]]; then
 
             # Anything inside `(...)' is added directly.
 
-            compadd "$expl[@]" - ${=action[2,-2]}
+            compadd "$subopts[@]" "$expl[@]" - ${=action[2,-2]}
           elif [[ "$action" = \{*\} ]]; then
 
             # A string in braces is evaluated.
@@ -230,12 +243,13 @@ if comparguments -i "$compconfig[autodescribe_options]" "$@"; then
             # Otherwise we call it with the description-arguments built above.
 
             action=( $=action )
-            ${(e)action[1]} "$expl[@]" ${(e)~action[2,-1]}
+            ${(e)action[1]} "$subopts[@]" "$expl[@]" ${(e)~action[2,-1]}
           fi
         fi
       fi
-      if [[ -z "$matched" ]] && _requested option &&
-          { ! _style option prefix || [[ "$PREFIX" = [-+]* ]] } ; then
+      if [[ -z "$matched" ]] && _requested options &&
+          { ! _style options prefix-needed yes ||
+            [[ "$PREFIX" = [-+]* ]] } ; then
         comparguments -M match
 
         if comparguments -s single; then
@@ -267,7 +281,7 @@ if comparguments -i "$compconfig[autodescribe_options]" "$@"; then
       fi
       if [[ -n "$opts" && -z "$aret$matched" &&
             nm -ne compstate[nmatches] ]] &&
-          _requested argument; then
+          _requested arguments; then
 
         local prefix suffix
 
@@ -282,7 +296,8 @@ if comparguments -i "$compconfig[autodescribe_options]" "$@"; then
 	  SUFFIX="$suffix"
 	  IPREFIX="${IPREFIX}${equal[1]%%:*}="
 	  matched=yes
-	  comparguments -L "$equal[1]" descr action
+	  comparguments -L "$equal[1]" descr action _sub_context
+          _sub_context="${oldsc}:${oldsc+${oldsc}-}${_sub_context}"
 	  continue
         fi
       fi
diff --git a/Completion/Base/_brace_parameter b/Completion/Base/_brace_parameter
index 9ed4867ef..1d1a48c78 100644
--- a/Completion/Base/_brace_parameter
+++ b/Completion/Base/_brace_parameter
@@ -1,6 +1,6 @@
 #compdef -brace-parameter-
 
-_parameters -e
+_tags any parameters && _parameters -e
 
 
 # Without the `-e' option, we would use the following (see the file
diff --git a/Completion/Base/_command_names b/Completion/Base/_command_names
index 889b330bd..8d8f5630f 100644
--- a/Completion/Base/_command_names
+++ b/Completion/Base/_command_names
@@ -4,38 +4,27 @@
 # complete only external commands and executable files. This and a
 # `-' as the first argument is then removed from the arguments.
 
-local nm=$compstate[nmatches] ret=1 expl ext
+local args defs
+
+defs=(
+  'commands:external command:compadd - ${(@k)commands}'
+  'executables:executable file or directory:_path_files -/g \*\(\*\)'
+)
 
 if [[ "$1" = -e ]]; then
-  ext=yes
-  shift
-elif [[ "$1" = - ]]; then
   shift
-fi
+else
+  [[ "$1" = - ]] && shift
 
-# Complete jobs in implicit fg and bg
-if [[ -z "$ext" && "$PREFIX[1]" = "%" ]]; then
-  _jobs
-  [[ nm -ne compstate[nmatches] ]] && return
+  defs=( "$defs[@]"
+    'jobs:: _jobs'
+    'builtins:builtin command:compadd - ${(@k)builtins}'
+    'functions:shell function:compadd - ${(@k)functions}'
+    'aliases:alias:compadd - ${(@k)aliases}'
+    'reserved-words:reserved word:compadd - ${(@k)reswords}'
+  )
 fi
 
-_description expl 'external command'
-compadd "$expl[@]" "$@" - "${(k@)commands}" && ret=0
+args=( "$@" )
 
-if [[ -z "$ext" ]]; then
-  _description expl 'builtin command'
-  compadd "$expl[@]" "$@" - "${(k@)builtins}" && ret=0
-  _description expl 'shell function'
-  compadd "$expl[@]" "$@" - "${(k@)functions}" && ret=0
-  _description expl 'alias'
-  compadd "$expl[@]" "$@" - "${(k@)aliases}" && ret=0
-  _description expl 'reserved word'
-  compadd "$expl[@]" "$@" - "${(k@)reswords}" && ret=0
-fi
-
-if [[ nm -eq compstate[nmatches] ]]; then
-  _description expl 'executable file or directory'
-  _path_files "$expl[@]" "$@" -/g "*(*)"
-else
-  return ret
-fi
+_alternative -O args any "$defs[@]"
diff --git a/Completion/Base/_condition b/Completion/Base/_condition
index 84c9fea20..93bbdc7f4 100644
--- a/Completion/Base/_condition
+++ b/Completion/Base/_condition
@@ -3,14 +3,13 @@
 local prev="$words[CURRENT-1]"
 
 if [[ "$prev" = -o ]]; then
+  _tags - -o options || return 1
+
   _options
 elif [[ "$prev" = -([no]t|ef) ]]; then
+  _tags - "$prev" files || return 1
+
   _files
 else
-  local ret=1
-
-  _files && ret=0
-  _parameters && ret=0
-
-  return ret
+  _alternative any 'files:: _files' 'parameters:: _parameters'
 fi
diff --git a/Completion/Base/_default b/Completion/Base/_default
index 4fb0b36dd..cf4077d3b 100644
--- a/Completion/Base/_default
+++ b/Completion/Base/_default
@@ -14,12 +14,13 @@ local expl
 
 # compcall || return 0
 
+_tags any files || return 1
+
 _description expl file
 _files "$expl[@]" && return
 
 # magicequalsubst allows arguments like <any-old-stuff>=~/foo to do
 # file name expansion after the =.  In that case, it's natural to
 # allow completion to handle file names after any equals sign.
-if [[ -o magicequalsubst ]] && compset -P 1 '*='; then
-  _files "$expl[@]"
-fi
+
+[[ -o magicequalsubst ]] && compset -P 1 '*=' && _files "$expl[@]"
diff --git a/Completion/Base/_describe b/Completion/Base/_describe
index 41c2ba8e5..db2011727 100644
--- a/Completion/Base/_describe
+++ b/Completion/Base/_describe
@@ -2,8 +2,8 @@
 
 # This can be used to add options or values with descriptions as matches.
 
-local cmd opt expl tmps tmpd tmpmd tmpms ret=1 showd _nm hide
-local type=value
+local cmd opt expl tmps tmpd tmpmd tmpms ret=1 showd _nm hide args
+local type=values
 
 cmd="$words[1]"
 
@@ -11,7 +11,7 @@ cmd="$words[1]"
 
 while getopts 'oc:' opt; do
   if [[ "$opt" = o ]]; then
-    type=option
+    type=options
   else
     cmd="$OPTARG"
   fi
@@ -20,9 +20,9 @@ shift OPTIND-1
 
 # Do the tests. `showd' is set if the descriptions should be shown.
 
-_tags -c "$cmd" "$type" || return 1
+_tags -c "$cmd" any "$type" || return 1
 
-_style "$type" describe && showd=yes
+_style "$type" description yes && showd=yes
 
 _description expl "$1"
 shift
@@ -33,7 +33,7 @@ else
   compdescribe -i "$@"
 fi
 
-[[ "$type" = option ]] && _style option hide && hide=yes
+[[ "$type" = options ]] && _style options prefix-hidden yes && hide=yes
 
 while compdescribe -g args tmpd tmpmd tmps tmpms; do
 
diff --git a/Completion/Base/_equal b/Completion/Base/_equal
index c50741ed4..760f85c68 100644
--- a/Completion/Base/_equal
+++ b/Completion/Base/_equal
@@ -1,8 +1,9 @@
 #compdef -equal-
 
-local expl
+local args
 
-_description expl alias
-compadd "$@" "$expl[@]" - "${(@k)aliases}"
-_description expl command
-compadd "$@" "$expl[@]" - "${(k@)commands}"
+args=( "$@" )
+
+_alternative -O args any \
+    'commands:command:compadd - ${(@k)commands}' \
+    'aliases:alias:compadd - ${(@k)aliases}'
diff --git a/Completion/Base/_jobs b/Completion/Base/_jobs
index 869aeeb8a..ba83d784e 100644
--- a/Completion/Base/_jobs
+++ b/Completion/Base/_jobs
@@ -1,6 +1,12 @@
 #autoload
 
-local expl disp jobs job jids
+local expl disp jobs job jids pfx='%' desc
+
+_tags any jobs || return 1
+
+_style jobs prefix-needed yes && [[ "$PREFIX" != %* ]] && return 1
+_style jobs prefix-hidden yes && pfx=''
+_style jobs description yes   && desc=yes
 
 if [[ "$1" = -r ]]; then
   jids=( "${(@k)jobstates[(R)running*]}" )
@@ -19,9 +25,13 @@ fi
 disp=()
 jobs=()
 for job in "$jids[@]"; do
-  disp=( "$disp[@]" "${(l:3:: ::%:)job} -- ${jobtexts[$job]}" )
+  [[ -n "$desc" ]] &&
+      disp=( "$disp[@]" "${pfx}${(r:2:: :)job} -- ${(r:COLUMNS-8:: :)jobtexts[$job]}" )
   jobs=( "$jobs[@]" "$job" )
 done
 
-compadd "$@" "$expl[@]" -ld disp - "%$^jobs[@]"
-
+if [[ -n "$desc" ]]; then
+  compadd "$@" "$expl[@]" -ld disp - "%$^jobs[@]"
+else
+  compadd "$@" "$expl[@]" - "%$^jobs[@]"
+fi
diff --git a/Completion/Base/_math b/Completion/Base/_math
index b9743d6b4..77d97acf1 100644
--- a/Completion/Base/_math
+++ b/Completion/Base/_math
@@ -9,4 +9,4 @@ if [[ "$SUFFIX" = *[^a-zA-Z0-9_]* ]]; then
   SUFFIX="${SUFFIX%%[^a-zA-Z0-9_]*}"
 fi
 
-_parameters
+_tags any parameters && _parameters
diff --git a/Completion/Base/_parameter b/Completion/Base/_parameter
index 1ede49e27..3ed91d620 100644
--- a/Completion/Base/_parameter
+++ b/Completion/Base/_parameter
@@ -1,6 +1,6 @@
 #compdef -parameter-
 
-_parameters -e
+_tags any parameters && _parameters -e
 
 # Without the `-e' option, we would use the following (see the file
 # Core/_parameters for more enlightenment).
diff --git a/Completion/Base/_subscript b/Completion/Base/_subscript
index 803893912..c5c6ca7e9 100644
--- a/Completion/Base/_subscript
+++ b/Completion/Base/_subscript
@@ -3,10 +3,14 @@
 local expl
 
 if [[ "$PREFIX" = :* ]]; then
+  _tags any char-classes || return 1
+
   _description expl 'character class'
   compadd "$expl[@]" -p: -S ':]' alnum alpha blank cntrl digit graph \
                                  lower print punct space upper xdigit
 elif [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then
+  _tags any association-keys || return 1
+
   _description expl 'association key'
   if [[ "$RBUFFER" = \]* ]]; then
     compadd "$expl[@]" -S '' - "${(@kP)${compstate[parameter]}}"
@@ -14,22 +18,39 @@ elif [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then
     compadd "$expl[@]" -S ']' - "${(@kP)${compstate[parameter]}}"
   fi
 elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then
-  local list i j
-
-  _description expl 'array index'
-  ind=( {1..${#${(P)${compstate[parameter]}}}} )
-  list=()
-  for i in "$ind[@]"; do
-    [[ "$i" = ${PREFIX}*${SUFFIX} ]] &&
-        list=( "$list[@]" 
-	  "${(r:4:: ::):)i} $(print -D ${(P)${compstate[parameter]}[$i]})" )
+  local list i j ret=1 disp
+
+  _tags any indexes parameters
+
+  while _tags; do
+    if _requested indexes; then
+      _description -V expl 'array index'
+      ind=( {1..${#${(P)${compstate[parameter]}}}} )
+      if _style indexes description yes; then
+        list=()
+        for i in "$ind[@]"; do
+          [[ "$i" = ${PREFIX}*${SUFFIX} ]] &&
+              list=( "$list[@]" 
+	             "${i}:$(print -D ${(P)${compstate[parameter]}[$i]})" )
+        done
+        compdisplay list ' -- ' "$list[@]"
+	disp=( -d list)
+      else
+        disp=()
+      fi
+
+      if [[ "$RBUFFER" = \]* ]]; then
+        compadd "$expl[@]" -S '' "$disp[@]" - "$ind[@]" && ret=0
+      else
+        compadd "$expl[@]" -S ']' "$disp[@]" - "$ind[@]" && ret=0
+      fi
+    fi
+    _requested parameters && _parameters && ret=0
+
+    (( ret )) || return 0
   done
 
-  if [[ "$RBUFFER" = \]* ]]; then
-    compadd "$expl[@]" -S '' -V default -d list - "$ind[@]"
-  else
-    compadd "$expl[@]" -S ']' -V default -d list - "$ind[@]"
-  fi
+  return 1
 else
   _compalso -math-
 fi
diff --git a/Completion/Base/_tilde b/Completion/Base/_tilde
index 0b81f75a1..afdca1222 100644
--- a/Completion/Base/_tilde
+++ b/Completion/Base/_tilde
@@ -4,40 +4,53 @@
 # for you or if there are too many of them, you may want to use
 # `compadd -qS/ - "$friends[@]"' or something like that.
 
-local d s dirs list lines revlines i
+local expl suf dirs list lines revlines i ret disp
 
 if [[ "$SUFFIX" = */* ]]; then
   ISUFFIX="/${SUFFIX#*/}$ISUFFIX"
   SUFFIX="${SUFFIX%%/*}"
-  s=(-S '')
+  suf=(-S '')
 else
-  s=(-qS/)
+  suf=(-qS/)
 fi
 
-if [[ -prefix [-+] ]]; then
-  lines=("$PWD" "$dirstack[@]")
-  integer i
-  if [[ ( -prefix - && ! -o pushdminus ) ||
-	( -prefix + && -o pushdminus ) ]]; then
-    revlines=( $lines )
-    for (( i = 1; i <= $#lines; i++ )); do
-      lines[$i]="$((i-1)) -- ${revlines[-$i]}"
-    done
-  else
-    for (( i = 1; i <= $#lines; i++ )); do
-      lines[$i]="$((i-1)) -- ${lines[$i]}"
-    done
+_tags any users named-directoriess directory-stack
+
+while _tags; do
+  _requested users && _users "$suf[@]" "$@" && ret=0
+  if _requested named-directories; then
+    _description expl 'named directory'
+    compadd "$suf[@]" "$expl[@]" "$@" - "${(@k)nameddirs}"
   fi
-  list=(${lines%% *})
-  compset -P '[-+]'
-  _description d 'directory stack'
-  compadd "$d[@]" -V dirs -S/ -ld lines -Q - "$list[@]" 
-else
-  _users "$@"
-  if (( $# )); then
-    d=( "$@" )
-  else
-    _description d 'named directory'
+
+  if _requested directory-stack &&
+     { ! _style directory-stack prefix-needed yes ||
+       [[ "$PREFIX" = [-+]* ]] }; then
+    if _style directory-stack description yes; then
+      integer i
+
+      lines=("${PWD}" "${dirstack[@]}")
+
+      if [[ ( -prefix - && ! -o pushdminus ) ||
+	    ( -prefix + && -o pushdminus ) ]]; then
+        revlines=( $lines )
+        for (( i = 1; i <= $#lines; i++ )); do
+          lines[$i]="$((i-1)) -- ${revlines[-$i]}"
+        done
+      else
+        for (( i = 1; i <= $#lines; i++ )); do
+          lines[$i]="$((i-1)) -- ${lines[$i]}"
+        done
+      fi
+      list=( ${PREFIX[1]}${^lines%% *} )
+      disp=( -ld lines )
+    else
+      list=( ${PREFIX[1]}{0..${#dirstack}} )
+      disp=()
+    fi
+
+    _description -V expl 'directory stack'
+    compadd "$expl[@]" "$suf[@]" "$disp[@]" -Q - "$list[@]" && ret=0
   fi
-  compadd "$d[@]" "$s[@]" - "${(@k)nameddirs}"
-fi
+  (( ret )) || return 0
+done
diff --git a/Completion/Base/_values b/Completion/Base/_values
index aac8b392d..e4d61d288 100644
--- a/Completion/Base/_values
+++ b/Completion/Base/_values
@@ -1,12 +1,27 @@
 #autoload
 
+local subopts
+
+if [[ "$1" = -O?* ]]; then
+  subopts=( "${(@P)1[3,-1]}" )
+  shift
+if [[ "$1" = -O ]]; then
+  subopts=( "${(@P)1}" )
+  shift 2
+else
+  subopts=()
+fi
+
 if compvalues -i "$@"; then
 
-  local noargs args opts descr action expl sep
+  local noargs args opts descr action expl sep _sub_context oldsc="$_sub_context"
 
   if ! compvalues -D descr action; then
 
-    _tags value || return 1
+    compvalues -C _sub_context
+    _sub_context="${oldsc}:${oldsc+${oldsc}-}${_sub_context}"
+
+    _tags "${_sub_context}" values || return 1
 
     compvalues -V noargs args opts
 
@@ -32,7 +47,8 @@ if compvalues -i "$@"; then
         PREFIX="$prefix"
 	SUFFIX="$suffix"
         IPREFIX="${IPREFIX}${args[1]%%:*}="
-	compvalues -L "${args[1]%%:*}" descr action
+	compvalues -L "${args[1]%%:*}" descr action _sub_context
+        _sub_context="${oldsc}:${oldsc+${oldsc}-}${_sub_context}"
       fi
     else
       compvalues -d descr
@@ -49,9 +65,12 @@ if compvalues -i "$@"; then
 
       return
     fi
+  else
+    compvalues -C _sub_context
+    _sub_context="${oldsc}:${oldsc+${oldsc}-}${_sub_context}"
   fi
 
-  _tags argument || return 1
+  _tags "${oldsc}:any" arguments || return 1
 
   _description expl "$descr"
 
@@ -85,13 +104,13 @@ if compvalues -i "$@"; then
 
       eval ws\=\( "${action[3,-3]}" \)
 
-      _describe "$descr" ws -M 'r:|[_-]=* r:|=*'
+      _describe "$descr" ws -M 'r:|[_-]=* r:|=*' "$subopts[@]"
 
     elif [[ "$action" = \(*\) ]]; then
 
       # Anything inside `(...)' is added directly.
 
-      compadd "$expl[@]" - ${=action[2,-2]}
+      compadd "$subopts[@]" "$expl[@]" - ${=action[2,-2]}
     elif [[ "$action" = \{*\} ]]; then
 
       # A string in braces is evaluated.
@@ -108,13 +127,11 @@ if compvalues -i "$@"; then
       # Otherwise we call it with the description-arguments built above.
 
       action=( $=action )
-      ${(e)action[1]} "$expl[@]" ${(e)~action[2,-1]}
+      ${(e)action[1]} "$subopts[@]" "$expl[@]" ${(e)~action[2,-1]}
     fi
   fi
 
   [[ nm -ne "$compstate[nmatches]" ]]
-  return
-
 else
   return 1;
 fi
diff --git a/Completion/Base/_vars b/Completion/Base/_vars
index a81a49f48..43cdf5d2c 100644
--- a/Completion/Base/_vars
+++ b/Completion/Base/_vars
@@ -4,8 +4,6 @@
 # `vared compconfig[<TAB>'.  However, in this version the [ must be
 # added by hand.
 
-local expl
-
 if [[ $PREFIX = *\[* ]]; then
   local var=${PREFIX%%\[*}
   local elt="${PREFIX#*\]}${SUFFIX%\]}"
@@ -16,9 +14,15 @@ if [[ $PREFIX = *\[* ]]; then
     addclose=(-S ']')
   fi
   if [[ ${(tP)var} = assoc* ]]; then
+    local expl
+
+    _tags subscript association-keys || return 1
+
     _description expl 'association key'
     compadd "$expl[@]" $addclose - ${(kP)var}
   fi
 else
-  _parameter
+  _tags any parameters || return 1
+
+  _parameters
 fi