zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH 1/4] run-help: Support variables in aliases
@ 2023-05-17 22:12 Jörg Sommer
  2023-05-17 22:12 ` [PATCH 2/4] run-help-ip: Reduce the match for link to l Jörg Sommer
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Jörg Sommer @ 2023-05-17 22:12 UTC (permalink / raw)
  To: zsh-workers; +Cc: Jörg Sommer

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/4] run-help-ip: Reduce the match for link to l
  2023-05-17 22:12 [PATCH 1/4] run-help: Support variables in aliases Jörg Sommer
@ 2023-05-17 22:12 ` Jörg Sommer
  2023-05-17 22:12 ` [PATCH 3/4] run-help-openssl: Reduce the code Jörg Sommer
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Jörg Sommer @ 2023-05-17 22:12 UTC (permalink / raw)
  To: zsh-workers; +Cc: Jörg Sommer

ip accepts the reduction of link to l.
---
 Functions/Misc/run-help-ip | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Functions/Misc/run-help-ip b/Functions/Misc/run-help-ip
index b811ce352..f635cce71 100644
--- a/Functions/Misc/run-help-ip
+++ b/Functions/Misc/run-help-ip
@@ -18,7 +18,7 @@ case $1 in
     (addrl*) man ip-addrlabel ;;
     (a*) man ip-address ;;
     (l2*) man ip-l2tp ;;
-    (li*) man ip-link ;;
+    (l*) man ip-link ;;
     (ma*) man ip-maddress ;;
     (mo*) man ip-monitor ;;
     (mr*) man ip-mroute ;;
-- 
2.40.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/4] run-help-openssl: Reduce the code
  2023-05-17 22:12 [PATCH 1/4] run-help: Support variables in aliases Jörg Sommer
  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 ` Jörg Sommer
  2023-05-17 22:12 ` [PATCH 4/4] run-help for docker, perf, podman, ssh, svnadmin Jörg Sommer
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Jörg Sommer @ 2023-05-17 22:12 UTC (permalink / raw)
  To: zsh-workers; +Cc: Jörg Sommer

---
 Functions/Misc/run-help-openssl | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/Functions/Misc/run-help-openssl b/Functions/Misc/run-help-openssl
index c528418c8..88293b252 100644
--- a/Functions/Misc/run-help-openssl
+++ b/Functions/Misc/run-help-openssl
@@ -1,7 +1 @@
-
-if [ $# -eq 0 ]; then
-    man openssl
-else
-    man $1
-fi
-
+man ${1:-openssl}
-- 
2.40.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/4] run-help for docker, perf, podman, ssh, svnadmin
  2023-05-17 22:12 [PATCH 1/4] run-help: Support variables in aliases Jörg Sommer
  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 ` Jörg Sommer
  2023-05-31 17:45   ` [PATCH v2] " Jörg Sommer
  2023-05-17 22:45 ` [PATCH 1/4] run-help: Support variables in aliases Bart Schaefer
  2023-05-23 16:25 ` [PATCH v2] run-help-openssl: Reduce code and use new manpages Jörg Sommer
  4 siblings, 1 reply; 9+ messages in thread
From: Jörg Sommer @ 2023-05-17 22:12 UTC (permalink / raw)
  To: zsh-workers; +Cc: Jörg Sommer

---
 Functions/Misc/run-help-docker   | 9 +++++++++
 Functions/Misc/run-help-perf     | 1 +
 Functions/Misc/run-help-podman   | 9 +++++++++
 Functions/Misc/run-help-ssh      | 6 ++++++
 Functions/Misc/run-help-svnadmin | 1 +
 5 files changed, 26 insertions(+)
 create mode 100644 Functions/Misc/run-help-docker
 create mode 100644 Functions/Misc/run-help-perf
 create mode 100644 Functions/Misc/run-help-podman
 create mode 100644 Functions/Misc/run-help-ssh
 create mode 100644 Functions/Misc/run-help-svnadmin

diff --git a/Functions/Misc/run-help-docker b/Functions/Misc/run-help-docker
new file mode 100644
index 000000000..09a8a221a
--- /dev/null
+++ b/Functions/Misc/run-help-docker
@@ -0,0 +1,9 @@
+if [[ $# == 0 ]]
+then
+    man docker
+elif [[ $# > 1 && $1 == (builder|checkpoint|config|container|context|image|manifest|network|node|plugin|secret|service|stack|swarm|system|trust|volume) ]]
+then
+    man docker-$1-$2
+else
+    man docker-$1
+fi
diff --git a/Functions/Misc/run-help-perf b/Functions/Misc/run-help-perf
new file mode 100644
index 000000000..2e0695af2
--- /dev/null
+++ b/Functions/Misc/run-help-perf
@@ -0,0 +1 @@
+man perf${1:+-$1}
diff --git a/Functions/Misc/run-help-podman b/Functions/Misc/run-help-podman
new file mode 100644
index 000000000..64d9cd83f
--- /dev/null
+++ b/Functions/Misc/run-help-podman
@@ -0,0 +1,9 @@
+if [[ $# == 0 ]]
+then
+    man podman
+elif [[ $# > 1 && $1 == (container|generate|healthcheck|image|kube|machine|manifest|network|pod|secret|system|volume) ]]
+then
+    man podman-$1-$2
+else
+    man podman-$1
+fi
diff --git a/Functions/Misc/run-help-ssh b/Functions/Misc/run-help-ssh
new file mode 100644
index 000000000..3ed9b3a09
--- /dev/null
+++ b/Functions/Misc/run-help-ssh
@@ -0,0 +1,6 @@
+if [[ $# -eq 0 ]]
+then
+    man ssh
+else
+    run-help $1
+fi
diff --git a/Functions/Misc/run-help-svnadmin b/Functions/Misc/run-help-svnadmin
new file mode 100644
index 000000000..dbddd6396
--- /dev/null
+++ b/Functions/Misc/run-help-svnadmin
@@ -0,0 +1 @@
+svnadmin help $1 | ${=PAGER:-more}
-- 
2.40.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] run-help: Support variables in aliases
  2023-05-17 22:12 [PATCH 1/4] run-help: Support variables in aliases Jörg Sommer
                   ` (2 preceding siblings ...)
  2023-05-17 22:12 ` [PATCH 4/4] run-help for docker, perf, podman, ssh, svnadmin Jörg Sommer
@ 2023-05-17 22:45 ` 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
  4 siblings, 2 replies; 9+ messages in thread
From: Bart Schaefer @ 2023-05-17 22:45 UTC (permalink / raw)
  To: Jörg Sommer; +Cc: zsh-workers

On Wed, May 17, 2023 at 3:13 PM Jörg Sommer <joerg@jo-so.de> wrote:
>
> 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.

This may not be the right way to handle this.  The same thing is
already being attempted in the block at

    (*)
        if ((! didman++))
        then

where you'll see

                # Discard the command itself & everything before it.

so I would have expected the existing recursive call to cover it.  If
recursion is NOT handling it, then maybe we need to pull that whole
thing up to before the original "whence" command?

Either way, we already have

    (*( is an alias for (noglob|nocorrect))*)

which would be made redundant by your addition of

+            elif [[ $expansion[1] == (noglob|nocorrect) ]]

I repeat my earlier remarks about "reaching the point of diminishing
returns" with our attempts to turn run-help into a full command-line
parser.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] run-help: Support variables in aliases
  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
  1 sibling, 0 replies; 9+ messages in thread
From: Jörg Sommer @ 2023-05-18  6:52 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1613 bytes --]

Bart Schaefer schrieb am Wed 17. May, 15:45 (-0700):
> On Wed, May 17, 2023 at 3:13 PM Jörg Sommer <joerg@jo-so.de> wrote:
> >
> > 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.
> 
> This may not be the right way to handle this.  The same thing is
> already being attempted in the block at
> 
>     (*)
>         if ((! didman++))
>         then
> 
> where you'll see
> 
>                 # Discard the command itself & everything before it.
> 
> so I would have expected the existing recursive call to cover it.  If
> recursion is NOT handling it, then maybe we need to pull that whole
> thing up to before the original "whence" command?

At least for me, the current code doesn't work:

```
% zsh -f
zenbook% lsb_release -d
Description:    Debian GNU/Linux 12 (bookworm)
zenbook% echo $ZSH_VERSION
5.9

zenbook% alias LCC='LC_ALL=C'; alias T='LCC true'
zenbook% run-help T
No manual entry for T
```

> Either way, we already have
> 
>     (*( is an alias for (noglob|nocorrect))*)

The patch eliminates this case, since the code to remove the variables also
belongs there.

> I repeat my earlier remarks about "reaching the point of diminishing
> returns" with our attempts to turn run-help into a full command-line
> parser.

I see. That's a fair point. What would be a better attempt to support
variables in aliases?

-- 
Dein Gesicht wird dir geschenkt. Lächeln musst du selbst! (Inga Hermann)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 269 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] run-help: Support variables in aliases
  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
  1 sibling, 0 replies; 9+ messages in thread
From: Peter Stephenson @ 2023-05-18  9:02 UTC (permalink / raw)
  To: Bart Schaefer, Jörg Sommer; +Cc: zsh-workers

> On 17/05/2023 23:45 Bart Schaefer <schaefer@brasslantern.com> wrote:
> 
>  
> On Wed, May 17, 2023 at 3:13 PM Jörg Sommer <joerg@jo-so.de> wrote:
> >
> > 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.
> 
> This may not be the right way to handle this.  The same thing is
> already being attempted in the block at
> 
>     (*)
>         if ((! didman++))
>         then
> 
> where you'll see
> 
>                 # Discard the command itself & everything before it.
> 
> so I would have expected the existing recursive call to cover it.

I think the key thing here is the line

	    if whence "run-help-$1:t" >/dev/null

so the bit you're talking about is only run if $1 has a run-help
subfunction.  Obviously this isn't Jörg's case.

What's going on at this point is a bit obscure, but I'm not
convinced the "discard options, parameter assignments and
paths" has anything to do with the zsh common line handling.
I think it's getting rid of anything in the arguments to the
command with the specialised run-help that might not help
the run-help-blah work.  So something like

mycmd var=var1 subcmd

is munged to run

run-help-mycmd subcmd

> If
> recursion is NOT handling it, then maybe we need to pull that whole
> thing up to before the original "whence" command?

I think this is actually an entirely different case, but someone
could authoritatively tell me I'm wrong.

pws


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2] run-help-openssl: Reduce code and use new manpages
  2023-05-17 22:12 [PATCH 1/4] run-help: Support variables in aliases Jörg Sommer
                   ` (3 preceding siblings ...)
  2023-05-17 22:45 ` [PATCH 1/4] run-help: Support variables in aliases Bart Schaefer
@ 2023-05-23 16:25 ` Jörg Sommer
  4 siblings, 0 replies; 9+ messages in thread
From: Jörg Sommer @ 2023-05-23 16:25 UTC (permalink / raw)
  To: zsh-workers; +Cc: Jörg Sommer

Openssl switches the naming of manpages to the common style
openssl-$SUBCOMMAND, e.g. openssl-enc. For backward compatibility try to
show the manpage with the old name if the new one doesn't exist.
---
 Functions/Misc/run-help-openssl | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/Functions/Misc/run-help-openssl b/Functions/Misc/run-help-openssl
index c528418c8..e4e45070e 100644
--- a/Functions/Misc/run-help-openssl
+++ b/Functions/Misc/run-help-openssl
@@ -1,7 +1 @@
-
-if [ $# -eq 0 ]; then
-    man openssl
-else
-    man $1
-fi
-
+man openssl${1:+-$1} || man ${1:-openssl}
-- 
2.40.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2] run-help for docker, perf, podman, ssh, svnadmin
  2023-05-17 22:12 ` [PATCH 4/4] run-help for docker, perf, podman, ssh, svnadmin Jörg Sommer
@ 2023-05-31 17:45   ` Jörg Sommer
  0 siblings, 0 replies; 9+ messages in thread
From: Jörg Sommer @ 2023-05-31 17:45 UTC (permalink / raw)
  To: zsh-workers; +Cc: Jörg Sommer

---
 Functions/Misc/run-help-docker   | 9 +++++++++
 Functions/Misc/run-help-perf     | 1 +
 Functions/Misc/run-help-podman   | 9 +++++++++
 Functions/Misc/run-help-ssh      | 6 ++++++
 Functions/Misc/run-help-svnadmin | 1 +
 5 files changed, 26 insertions(+)
 create mode 100644 Functions/Misc/run-help-docker
 create mode 100644 Functions/Misc/run-help-perf
 create mode 100644 Functions/Misc/run-help-podman
 create mode 100644 Functions/Misc/run-help-ssh
 create mode 100644 Functions/Misc/run-help-svnadmin

diff --git a/Functions/Misc/run-help-docker b/Functions/Misc/run-help-docker
new file mode 100644
index 000000000..09a8a221a
--- /dev/null
+++ b/Functions/Misc/run-help-docker
@@ -0,0 +1,9 @@
+if [[ $# == 0 ]]
+then
+    man docker
+elif [[ $# > 1 && $1 == (builder|checkpoint|config|container|context|image|manifest|network|node|plugin|secret|service|stack|swarm|system|trust|volume) ]]
+then
+    man docker-$1-$2
+else
+    man docker-$1
+fi
diff --git a/Functions/Misc/run-help-perf b/Functions/Misc/run-help-perf
new file mode 100644
index 000000000..2e0695af2
--- /dev/null
+++ b/Functions/Misc/run-help-perf
@@ -0,0 +1 @@
+man perf${1:+-$1}
diff --git a/Functions/Misc/run-help-podman b/Functions/Misc/run-help-podman
new file mode 100644
index 000000000..64d9cd83f
--- /dev/null
+++ b/Functions/Misc/run-help-podman
@@ -0,0 +1,9 @@
+if [[ $# == 0 ]]
+then
+    man podman
+elif [[ $# > 1 && $1 == (container|generate|healthcheck|image|kube|machine|manifest|network|pod|secret|system|volume) ]]
+then
+    man podman-$1-$2
+else
+    man podman-$1
+fi
diff --git a/Functions/Misc/run-help-ssh b/Functions/Misc/run-help-ssh
new file mode 100644
index 000000000..9c48596ff
--- /dev/null
+++ b/Functions/Misc/run-help-ssh
@@ -0,0 +1,6 @@
+if [[ $# < 2 ]]
+then
+    man ssh
+else
+    run-help $2
+fi
diff --git a/Functions/Misc/run-help-svnadmin b/Functions/Misc/run-help-svnadmin
new file mode 100644
index 000000000..dbddd6396
--- /dev/null
+++ b/Functions/Misc/run-help-svnadmin
@@ -0,0 +1 @@
+svnadmin help $1 | ${=PAGER:-more}
-- 
2.40.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-05-31 17:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-17 22:12 [PATCH 1/4] run-help: Support variables in aliases Jörg Sommer
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-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

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).