Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: pws-21: _vars



This extends the _vars completion, used after things like read and vared,
to allow completion of the keys of associative arrays.  However, the [ has
to be added by hand because it can't tell whether you want
the parameter or an element.  Maybe there's a case for autoparamkeys
behaviour --- but that would need sensitivity to the command context, which
isn't really on.

--- Completion/Base/_vars.old	Tue Apr 13 09:37:37 1999
+++ Completion/Base/_vars	Thu Jun 10 12:17:04 1999
@@ -1,3 +1,20 @@
 #compdef getopts read unset vared
 
-compgen -v
+# This will handle completion of keys of associative arrays, e.g. at
+# `vared compconfig[<TAB>'.  However, in this version the [ must be
+# added by hand.
+
+if [[ $PREFIX = *\[ ]]; then
+  local var=${PREFIX%%\[*}
+  local elt="${PREFIX#*\]}${SUFFIX%\]}"
+  local addclose
+  compset -p $(( ${#var} + 1 ))
+  if ! compset -S \]; then
+    addclose=(-S ']')
+  fi
+  if [[ ${(tP)var} = assoc* ]]; then
+    compadd $addclose ${(kP)var}
+  fi
+else
+  compgen -v
+fi

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



Messages sorted by: Reverse Date, Date, Thread, Author