zsh-workers
 help / color / mirror / code / Atom feed
From: Marlon Richert <marlon.richert@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Let run-help filter cmd_args before calling run-help-<command> (was Re: [RFC][PATCH] Try calling command with help flags in run-help)
Date: Fri, 4 Jun 2021 00:26:58 +0300	[thread overview]
Message-ID: <CAHLkEDuPgBaNoGyu-io=0HKB1FxOpHGoHYUXHQSrwztMuEMVAw@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7YZVzbKde3NOaDxYSzJRwyWRTLc=RHOX4XATSBOT=Tvcw@mail.gmail.com>

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

On Thu, Jun 3, 2021 at 7:34 AM Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Wed, Jun 2, 2021 at 1:58 PM Marlon Richert <marlon.richert@gmail.com> wrote:
> > And here's another part of workers 48926 as a separate patch.
>
> run-help:115: parse error near `]'
>
> Typo?
> +                shift -p (( $#cmd_args + 1 - cmd_args[(i)(-|--|;)] )) cmd_args

Apparently. But I've removed that line now in the new version of the
patch (attached).

> This change also breaks the run-help-ssh example in the documentation,
> and does so in a way I think it's impossible to fix.
>
> Stupid example, but:
>
> % ssh -- localhost date
>
> Without the patch, run-help displays help for the "date" command.
> With it, help for "ssh".

That's weird. For me, it gets help for 'ssh', both before and after
the patch (on commit bd328a2).

> It would not surprise me to find that attempting to generically parse
> arguments in run-help would also break helpers for commands like "su"
> and "sudo",

I tried it, but it doesn't seem to be the case.

> or some commands that have git-style sub-commands.

My patch actually fixes an annoying case with 'run-help git'. Try
pressing ^[h on, for example, 'git -C /path/to/zsh log'. Without my
patch, it gives

% run-help git
git is /usr/bin/git
error: invalid key: alias.-C
No manual entry for git--C

With my patch, it correctly displays help for 'git log'.

Anyway, here's a new version of my patch. Let me know what you think.

[-- Attachment #2: 0001-Let-run-help-filter-cmd_args-before-calling-run-help.txt --]
[-- Type: text/plain, Size: 3191 bytes --]

From 1d2349c0d9dcaaa8b464741ed5a608c6f1eb32d1 Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlon.richert@gmail.com>
Date: Fri, 4 Jun 2021 00:22:59 +0300
Subject: [PATCH] Let run-help filter $cmd_args before calling
 run-help-<command>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

…to make it easier to write run-help-<command> functions.
---
 Functions/Misc/run-help       | 15 +++++++++------
 Functions/Misc/run-help-btrfs |  4 ----
 Functions/Misc/run-help-ip    |  4 ----
 Functions/Misc/run-help-p4    |  2 +-
 Functions/Misc/run-help-svk   |  2 +-
 Functions/Misc/run-help-svn   |  2 +-
 6 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help
index e351dd6a6..919899a13 100644
--- a/Functions/Misc/run-help
+++ b/Functions/Misc/run-help
@@ -101,12 +101,15 @@ do
 		builtin getln cmd_args
 		builtin print -z "$cmd_args"
 		cmd_args=( ${(z)cmd_args} )
-		# Discard environment assignments, etc.
-		while [[ $cmd_args[1] != ${run_help_orig_cmd:-$1} ]]
-		do
-		    shift cmd_args || return 1
-		done
-		eval "run-help-$1:t ${(q@)cmd_args[2,-1]}"
+                
+                # Discard the command itself & everything before it.
+                shift $cmd_args[(i)${run_help_orig_cmd:-$1}] cmd_args ||
+                    return
+                
+                # Discard options, parameter assignments & paths.
+                cmd_args=( ${cmd_args[@]:#([-+]*|*=*|*/*|\~*)} )
+                
+                eval "run-help-$1:t ${(@q)cmd_args}"
 	    else
 		POSIXLY_CORRECT=1 man $@:t
 	    fi
diff --git a/Functions/Misc/run-help-btrfs b/Functions/Misc/run-help-btrfs
index 0dc1dabcb..cb139e9b7 100644
--- a/Functions/Misc/run-help-btrfs
+++ b/Functions/Misc/run-help-btrfs
@@ -1,7 +1,3 @@
-while [[ $# != 0 && $1 == -* ]]; do
-    shift
-done
-
 case $1 in
     (b*)    man btrfs-balance          ;;
     (c*)    man btrfs-check            ;;
diff --git a/Functions/Misc/run-help-ip b/Functions/Misc/run-help-ip
index 8807f9ef1..b811ce352 100644
--- a/Functions/Misc/run-help-ip
+++ b/Functions/Misc/run-help-ip
@@ -14,10 +14,6 @@ if ! man -w ip-address >/dev/null 2>&1; then
     return
 fi
 
-while [[ $# != 0 && $1 == -* ]]; do
-    shift
-done
-
 case $1 in
     (addrl*) man ip-addrlabel ;;
     (a*) man ip-address ;;
diff --git a/Functions/Misc/run-help-p4 b/Functions/Misc/run-help-p4
index 662ce94fe..e48a4d068 100644
--- a/Functions/Misc/run-help-p4
+++ b/Functions/Misc/run-help-p4
@@ -2,4 +2,4 @@ if (( ! $# )); then
   p4 help commands
 else
   p4 help $1
-fi | ${=PAGER:-less}
+fi | ${=PAGER:-more}
diff --git a/Functions/Misc/run-help-svk b/Functions/Misc/run-help-svk
index 92438a53f..782538246 100644
--- a/Functions/Misc/run-help-svk
+++ b/Functions/Misc/run-help-svk
@@ -1 +1 @@
-svk help ${${@:#-*}[1]} | ${=PAGER:-more}
+svk help $1 | ${=PAGER:-more}
diff --git a/Functions/Misc/run-help-svn b/Functions/Misc/run-help-svn
index 5d1068588..d55a493a6 100644
--- a/Functions/Misc/run-help-svn
+++ b/Functions/Misc/run-help-svn
@@ -1 +1 @@
-svn help ${${@:#-*}[1]} | ${=PAGER:-more}
+svn help $1 | ${=PAGER:-more}
-- 
2.30.1 (Apple Git-130)


  parent reply	other threads:[~2021-06-03 21:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-25 20:47 [RFC][PATCH] Try calling command with help flags in run-help Marlon Richert
2021-05-25 20:57 ` Bart Schaefer
2021-06-02 18:26   ` [PATCH] Let run-help try to show function source from file (was Re: [RFC][PATCH] Try calling command with help flags in run-help) Marlon Richert
2021-06-20 21:23     ` Lawrence Velázquez
2021-07-18 18:38       ` Lawrence Velázquez
2021-07-28  2:03       ` Bart Schaefer
2021-06-02 20:58   ` Let run-help filter cmd_args before calling run-help-<command> " Marlon Richert
2021-06-03  4:34     ` Bart Schaefer
2021-06-03  4:38       ` Bart Schaefer
2021-06-03 21:26       ` Marlon Richert [this message]
2021-06-03 21:45         ` Lawrence Velázquez
2021-06-03 21:52           ` Bart Schaefer
2021-06-03 22:00             ` Lawrence Velázquez
2021-06-03 23:33         ` Bart Schaefer
2021-06-05 19:15           ` Marlon Richert
2021-06-20 18:01             ` Lawrence Velázquez
2021-07-18 18:45               ` Lawrence Velázquez
2021-07-28 17:58                 ` Bart Schaefer
2021-07-29 12:11                   ` Marlon Richert
2021-07-30 16:55                     ` Bart Schaefer

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='CAHLkEDuPgBaNoGyu-io=0HKB1FxOpHGoHYUXHQSrwztMuEMVAw@mail.gmail.com' \
    --to=marlon.richert@gmail.com \
    --cc=schaefer@brasslantern.com \
    --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).