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

PATCH: New _read and selective parameter completion



This adds an _arguments based completion function for read. I don't think
we have too many builtins left where conversion to use _arguments would
still be useful. Any requests?       

I thought about modifying _vars to insert the '[' for arrays and
associations but _parameters would first need to be given an option to
make it only complete specific types of parameter. Would anyone object
to my adding this? I was thinking of a -g option (analogous to the -g
option of _files) where the pattern specified would be augmented with
~*local* and used to match the values in the $parameters association.

I mentioned this vaguely before in 11284 and Sven had some good ideas
in his reply (11293). The focus there is more towards having the
patterns configurable via a style similar to the file-patterns tag but
my suggested option would I think be a useful first step.

Oliver

Index: Completion/Builtins/_read
===================================================================
RCS file: _read
diff -N _read
--- /dev/null	Tue May  5 13:32:27 1998
+++ _read	Wed Aug  9 14:09:15 2000
@@ -0,0 +1,18 @@
+#compdef read
+
+local pflag expl line curcontext="$curcontext"
+
+# -p flag only relevant if we have a coprocess
+(:>&p) 2>/dev/null &&
+  pflag='(-q -u -z)-p[input is read from the coprocess]'
+
+_arguments -C -s \
+  '-r[raw mode]' \
+  '(-p -k -u -z)-q[read y or n character from terminal]' \
+  '(-q)-k[specify number of characters to read]:number of characters' \
+  '(-q -u -p)-z[read entry from editor buffer stack]' \
+  '(-E)-e[input read is echoed and not assigned]' \
+  '(-e)-E[input read is echoed]' \
+  '-A[first name is taken as an array]' \
+  '(-q -z -p)-u+[specify file-descriptor to read from]:file-descriptor:_file_descriptors' \
+  $pflag '1:varprompt:_vars -qS\?' '*:vars:_vars'
Index: Completion/Builtins/_vars
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_vars,v
retrieving revision 1.3
diff -u -r1.3 _vars
--- Completion/Builtins/_vars	2000/05/31 09:38:26	1.3
+++ Completion/Builtins/_vars	2000/08/09 21:09:15
@@ -1,4 +1,4 @@
-#compdef getopts read unset vared
+#compdef getopts unset vared
 
 # This will handle completion of keys of associative arrays, e.g. at
 # `vared foo[<TAB>'.  However, in this version the [ must be added
@@ -20,5 +20,5 @@
         compadd $addclose -k "$var"
   fi
 else
-  _parameters
+  _parameters "$@"
 fi



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