zsh-workers
 help / color / mirror / code / Atom feed
From: "Jörg Sommer" <joerg@jo-so.de>
To: zsh-workers@zsh.org
Cc: "Jörg Sommer" <joerg@jo-so.de>
Subject: [PATCH 1/4] run-help: Support variables in aliases
Date: Thu, 18 May 2023 00:12:44 +0200	[thread overview]
Message-ID: <2322b9b9b46c585516c4347ad3b07a9db26f0a7f.1684361567.git.joerg@jo-so.de> (raw)

If the alias definition starts with a variable assignment, run-help fails,
because it sees the variable assignment as command. Hence, skip all
variable assignments and noglob|nocorrect thereafter.

Example:

% alias LCC='LC_ALL=C'
% alias T='LCC true'
% run-help T
---
 Functions/Misc/run-help | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help
index 462044b72..438f76122 100644
--- a/Functions/Misc/run-help
+++ b/Functions/Misc/run-help
@@ -56,13 +56,28 @@ do
     [[ -n $noalias && $what = *" is an alias "* ]] && continue
     builtin print -r $what
     case $what in
-    (*( is an alias for (noglob|nocorrect))*)
-	[[ ${what[(w)7]:t} != ${what[(w)1]} ]] &&
-	  run_help_orig_cmd=${what[(w)1]} run-help ${what[(w)7]:t} ${(z)${what[(w)8,-1]}}
-	;;
     (*( is an alias)*)
-	[[ ${what[(w)6]:t} != ${what[(w)1]} ]] &&
-	  run_help_orig_cmd=${what[(w)1]} run-help ${what[(w)6]:t} ${(z)${what[(w)7,-1]}}
+        local expansion=( ${${=what}[6,-1]} )
+        while true
+        do
+            if [[ $expansion[1] == *=* ]]
+            then
+                shift expansion
+            elif [[ $expansion[1] == (noglob|nocorrect) ]]
+            then
+                shift expansion
+                break
+            elif [[ $expansion[1] != $1 ]] && alias $expansion[1] >/dev/null
+            then
+                expansion=( ${=$(builtin whence $expansion[1])} $expansion[2,-1] )
+            else
+                break
+            fi
+        done
+
+        expansion[1]=$expansion[1]:t
+        [[ $expansion[1] != ${what[(w)1]} ]] &&
+          run_help_orig_cmd=${what[(w)1]} run-help $expansion[@]
 	;;
     (*( is a * function))
 	case ${what[(w)1]} in
-- 
2.40.1



             reply	other threads:[~2023-05-17 22:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-17 22:12 Jörg Sommer [this message]
2023-05-17 22:12 ` [PATCH 2/4] run-help-ip: Reduce the match for link to l Jörg Sommer
2023-05-17 22:12 ` [PATCH 3/4] run-help-openssl: Reduce the code Jörg Sommer
2023-05-17 22:12 ` [PATCH 4/4] run-help for docker, perf, podman, ssh, svnadmin Jörg Sommer
2023-05-31 17:45   ` [PATCH v2] " Jörg Sommer
2023-09-20 22:41     ` Oliver Kiddle
2023-09-23  7:16       ` Jörg Sommer
2023-09-23 15:57         ` Bart Schaefer
2023-09-24  7:31           ` Jörg Sommer
2023-05-17 22:45 ` [PATCH 1/4] run-help: Support variables in aliases Bart Schaefer
2023-05-18  6:52   ` Jörg Sommer
2023-05-18  9:02   ` Peter Stephenson
2023-05-23 16:25 ` [PATCH v2] run-help-openssl: Reduce code and use new manpages Jörg Sommer

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=2322b9b9b46c585516c4347ad3b07a9db26f0a7f.1684361567.git.joerg@jo-so.de \
    --to=joerg@jo-so.de \
    --cc=zsh-workers@zsh.org \
    /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).