zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@u.genie.co.uk>
To: Zsh workers <zsh-workers@sunsite.auc.dk>
Subject: PATCH: use of _arguments for hash
Date: Fri, 12 May 2000 14:10:59 +0100	[thread overview]
Message-ID: <391C02E3.A38C73CA@u.genie.co.uk> (raw)

This adds _arguments based completion for the hash (and rehash)
builtins. Why does rehash accept the -v option when as far as I can
tell, it can never do anything? Would it be useful to add a -L option
to hash similar to alias -L?

I'm getting one problem with this completion: when I type hash -r<tab>,
it is completed to 'hash -d '. I would expect it to complete to
'hash -rd '. I also get 'no more arguments' duplicated after
'hash -d -v<tab>'.

I've also added the + options in _vars_eq for typeset now that the bug
with them is fixed (thanks Sven).

Oliver

Index: Completion/Builtins/_hash
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_hash,v
retrieving revision 1.3
diff -u -r1.3 _hash
--- _hash       2000/05/02 08:23:31     1.3
+++ _hash       2000/05/12 13:05:53
@@ -1,16 +1,37 @@
-#compdef hash
+#compdef hash rehash

-local expl
+local state line expl common_args curcontext="$curcontext"
+typeset -A opt_args

-if [[ "$words[2]" = -*d* ]]; then
-  if compset -P 1 '*='; then
-    _wanted -C -d-value files expl directories _path_files -/
+common_args=( \
+  '-d[use named directory hash table]' \
+  '(-r -m -v)-f[rebuild hash table]' )
+
+case ${words[1]} in
+  hash)
+    _arguments -C -s \
+      '(-f -m -v)-r[empty hash table]' \
+      '(-f -r)-m[treat arguments as patterns]' \
+      '(-f -r -m)-v[list entires as they are added]' \
+      "${common_args[@]}" \
+      '(-d -f -r -m -v)*:hash:->hashval' && return 0
+  ;;
+  rehash)
+    _arguments -C -s ${common_args[@]} && return 0
+  ;;
+esac
+
+if [[ $state = hashval ]]; then
+  if (( $+opt_args[-d] )); then
+    if compset -P 1 '*='; then
+      _wanted -C value files expl directories _path_files -/
+    else
+      _wanted -C name named-directories expl 'named directory' \
+          compadd -q -S '=' - "${(@k)nameddirs}"
+    fi
+  elif compset -P 1 '*='; then
+    _wanted -C value values expl 'executable file' _files -g '*(-*)'
   else
-    _wanted -C -d named-directories expl 'named directory' \
-        compadd -q -S '=' - "${(@k)nameddirs}"
+    _wanted -C name commands expl command compadd -q -S '=' - "${(@k)commands}"
   fi
-elif compset -P 1 '*='; then
-  _wanted -C value values expl 'executable file' _files -g '*(-*)'
-else
-  _wanted -C name commands expl command compadd -q -S '=' - "${(@k)commands}"
 fi
Index: Completion/Builtins/_vars_eq
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_vars_eq,v
retrieving revision 1.4
diff -u -r1.4 _vars_eq
--- _vars_eq    2000/05/09 16:53:34     1.4
+++ _vars_eq    2000/05/12 13:05:53
@@ -17,19 +17,19 @@
   Z '(-A -E -F -f -i)-Z+[right justify and fill with leading zeros]:width' \
   a '(-A -E -F -T -f -i)-a[specify that arguments refer to arrays]' \
   f '(-A -E -F -L -R -T -Z -a -g -h -i -l -r -x)-f[specify that arguments refer to functions]' \
-  g '(-T -f)-g[do not restrict parameter to local scope]' \
-  h '(-T -f)-h[hide parameter]' \
-  i '(-A -E -F -T -f)-i[represent internally as an integer]' \
+  g '(-T -f)-+g[do not restrict parameter to local scope]' \
+  h '(-T -f)-+h[hide parameter]' \
+  i '(-A -E -F -T -f)-+i[represent internally as an integer]' \
   l '(-T -f)-l[convert the value to lowercase]' \
   m '(-A -E -F -T -i)-m[treat arguments as patterns]' \
-  r '(-f)-r[mark parameters as readonly]' \
-  t '(-T)-t[tag parameters and turn on execution tracing for functions]' \
-  tf '(-T)-t[turn on execution tracing for functions]' \
-  tp '(-T)-t[tag parameters]' \
+  r '(-f)-+r[mark parameters as readonly]' \
+  t '(-T)-+t[tag parameters and turn on execution tracing for functions]' \
+  tf '(-T)-+t[turn on execution tracing for functions]' \
+  tp '(-T)-+t[tag parameters]' \
   u '-u[convert the value to uppercase or mark function for autoloading]' \
   uf '-u[mark function for autoloadling]' \
   up '-u[convert the value to uppercase]' \
-  x '(-f)-x[export parameter]' )
+  x '(-f)-+x[export parameter]' )

 use="AEFLRTUZafghilmrtux"


             reply	other threads:[~2000-05-12 13:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-05-12 13:10 Oliver Kiddle [this message]
2000-05-12 14:33 Sven Wischnowsky
2000-05-12 14:49 ` Bart Schaefer
2000-05-12 17:46   ` Peter Stephenson
2000-05-14 23:24 ` Oliver Kiddle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=391C02E3.A38C73CA@u.genie.co.uk \
    --to=opk@u.genie.co.uk \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).