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

PATCH: new _zpty, _getconf and improved _compdef



_compdef predated _arguments so I've brought it up-to-date, made it handle all the options and use the prefix-hidden style to decide whether to list the '_' prefix for completion functions.

_zpty is new. Is there a better way for me to have done the equivalent of :*:nothing:_nothing for the -r option?

I wrote _getconf to make it easier to play with /usr/bin/getconf after noticing the getconf builtin to ksh93 (I hadn't known of the command before). If it turns out to be too system specific then it probably isn't worth the hassle of including it: Linux appears to offer more configuration variables (I used AIX's) but this completion is still useful on it. IRIX has two separate commands - pathconf and sysconf but I appear to only have the man pages and not the commands so I didn't do the fairly trivial changes to handle them.

If anyone feels the need to implement getconf as a builtin, I'd suggest that the non-path dependant variables might be better done as an associative array however I personally think it would be a fairly pointless thing to do unless you can't bare it for ksh to have a feature that zsh doesn't.

Oliver

--- Completion/Builtins/_compdef.old	Mon Feb 21 12:46:38 2000
+++ Completion/Builtins/_compdef	Thu Mar  9 10:56:12 2000
@@ -1,24 +1,39 @@
 #compdef compdef
 
-local expl func base=2
+local state line expl list disp
 
-while [[ $words[base] = -* ]]; do
-  case $words[base] in
-    -d) delete=yes ;;
-    -p) type=pattern ;;
-    -k) type=key ;;
-  esac  
-  (( base++ ))
-done
+_arguments -C -s \
+  '(-d)-a[make function autoloadable]' \
+  '(-d -p -P)-n[leave existing definitions intact]' \
+  '(-a -n -p -P -k -K)-d[delete]:*:completed command:->ccom' \
+  '(-n -d -P -k -K)-p[completion for command matching pattern]:completion function:->cfun:pattern' \
+  '(-n -d -p -k -K)-P[as -p for commands without own completion]:completion function:->cfun:pattern' \
+  '(-d -p -P -K)-k[define widget and key binding]:completion function:->cfun:widget name::style:->style:*:key' \
+  '(-d -p -P -k)-K[define multiple widgets based on function]:completion function:->cfun:widget name::style:->style:*:key' \
+  '1:completion function:->cfun' \
+  '2:commands:_command_names'
+  
 
-if [ "$delete" ]; then
-  _wanted commands expl 'completed command' &&
-      compadd "$expl[@]" - ${(k)_comps}
-else
-  if [[ CURRENT -eq base ]]; then
-    _wanted functions expl 'completion function' &&
-        compadd "$expl[@]" - ${^fpath:/.}/_(|*[^~])(N:t)
-  else
-    _command_names
-  fi
-fi
+case $state in
+  ccom)
+    _wanted commands expl 'completed command' &&
+        compadd "$expl[@]" - ${(k)_comps}
+  ;;
+  cfun)
+    if _wanted functions expl 'completion function'; then
+      list=( ${^fpath:/.}/_(|*[^~])(N:t) )
+      if zstyle -T ":completion:${curcontext}" prefix-hidden; then
+        disp=( ${list[@]#_} )
+        compadd "$expl[@]" -d disp - "$list[@]"
+      else
+        compadd "$expl[@]" - "$list[@]"
+      fi
+    fi
+  ;;
+  style)
+    _wanted widgetstyle expl 'widget style' &&
+        compadd complete-word delete-char-or-list expand-or-complete \
+        expand-or-complete-prefix list-choices menu-complete \
+        menu-expand-or-complete reverse-menu-complete
+  ;;
+esac
--- /dev/null	Thu Mar  9 11:13:20 2000
+++ Completion/Builtins/_zpty	Thu Mar  9 11:09:03 2000
@@ -0,0 +1,23 @@
+#compdef zpty
+
+local state line list names expl
+
+_arguments -C -s \
+  '(-d -w -r -L)-e[echo input characters]' \
+  '(-d -w -r -L)-b[io to pseudo-terminal blocking]' \
+  '(-e -b -w -r -L)-d[delete command]:*:name:->name' \
+  '(-e -b -d -r -L)-w[send string to command]:name:->name:*:strings to write' \
+  '(-e -b -d -w -L)-r[read string from command]:name:->name:param:_parameters:*:nothing:_nothing' \
+  '(-e -b -d -w -r)-L[list defined commands as calls]' \
+  '*::args:_normal'
+
+if [[ $state = name ]] && _wanted zptynames expl 'zpty command names'; then
+  list=( ${${(f)"$(zpty)"}#*\) } )
+  names=( ${list%%:*} )
+  if zstyle -T ":completion:${curcontext}" verbose; then
+    zformat -a list ' --' ${${(f)"$(zpty)"}#*\) }
+    compadd "$expl[@]" -d list - "$names[@]"
+  else
+    compadd "$expl[@]" - "$names[@]"
+  fi
+fi
--- /dev/null	Thu Mar  9 11:13:20 2000
+++ Completion/User/_getconf	Wed Mar  8 15:23:44 2000
@@ -0,0 +1,37 @@
+#compdef getconf
+
+local expl
+
+if [[ CURRENT -eq 2 ]]; then
+  _tags syswideconfig pathconfig standardsconfig
+
+  while _tags; do
+    if _requested -V syswideconfig expl 'systemwide configuration variables'
+    then
+      compadd "$expl[@]" -S '' ARG_MAX BC_BASE_MAX BC_DIM_MAX BC_SCALE_MAX \
+          BC_STRING_MAX CHILD_MAX COLL_WEIGHTS_MAX EXPR_NEST_MAX LINE_MAX \
+	  NGROUPS_MAX OPEN_MAX RE_DUP_MAX STREAM_MAX TZNAME_MAX
+    fi
+    if _requested -V standardsconfig \
+        expl 'system-standards configuration variables'; then
+      compadd "$expl[@]" -S '' _POSIX_CHILD_MAX _POSIX_LINK_MAX \
+          _POSIX_MAX_CANON _POSIX_MAX_INPUT _POSIX_NAME_MAX _POSIX_NGROUPS_MAX \
+	  _POSIX_OPEN_MAX _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX \
+	  _POSIX_STREAM_MAX _POSIX_TZNAME_MAX _POSIX_VERSION \
+	  POSIX2_BC_BASE_MAX POSIX2_BC_DIM_MAX POSIX2_BC_SCALE_MAX \
+	  POSIX2_BC_STRING_MAX POSIX2_COLL_WEIGHTS_MAX POSIX2_EXPR_NEST_MAX \
+	  POSIX2_LINE_MAX POSIX2_RE_DUP_MAX POSIX2_VERSION POSIX2_C_BIND \
+	  POSIX2_C_DEV POSIX2_FORT_DEV POSIX2_FORT_RUN POSIX2_LOCALEDEF \
+	  POSIX2_SW_DEV _XOPEN_VERSION
+    fi
+    if _requested -V pathconfig expl 'system path configuration variables'
+    then
+      compadd "$expl[@]" -S '' PIPE_BUF _POSIX_CHOWN_RESTRICTED \
+          _POSIX_NO_TRUNC _POSIX_VDISABLE
+      compadd "$expl[@]" -S ' ' LINK_MAX MAX_CANON MAX_INPUT NAME_MAX PATH_MAX \
+          PIPE_BUF
+    fi
+  done
+else
+  _files -/
+fi



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