* [RFC][PATCH] Try calling command with help flags in run-help
@ 2021-05-25 20:47 Marlon Richert
2021-05-25 20:57 ` Bart Schaefer
0 siblings, 1 reply; 20+ messages in thread
From: Marlon Richert @ 2021-05-25 20:47 UTC (permalink / raw)
To: Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 139 bytes --]
When there isn't a man page, try calling the command with --help or -h.
Additionally, be a bit smarter about showing function source code.
[-- Attachment #2: 0001-Try-calling-command-with-help-flags-in-run-help.txt --]
[-- Type: text/plain, Size: 4160 bytes --]
From ba0fa464c73b10decb33582156aa214953cdd861 Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlon.richert@gmail.com>
Date: Tue, 25 May 2021 23:45:28 +0300
Subject: [PATCH] Try calling command with help flags in run-help
When there isn't a man page, try calling the command with --help or -h.
Additionally, be a bit smarter about showing function source code.
---
Functions/Misc/run-help | 108 ++++++++++++++++++++++++++++++----------
1 file changed, 81 insertions(+), 27 deletions(-)
diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help
index e351dd6a6..dc0490342 100644
--- a/Functions/Misc/run-help
+++ b/Functions/Misc/run-help
@@ -8,6 +8,17 @@
# autoload -Uz run-help
#
+.run-help.eval() {
+ output="$( eval "COLUMNS=$COLUMNS $1" 2>&1 )" ||
+ return
+
+ [[ -n $output ]] ||
+ return
+
+ print "$output" | ${=PAGER:-more}
+}
+
+run-help() {
emulate -RL zsh
local HELPDIR="${HELPDIR:-@runhelpdir@}"
@@ -64,13 +75,6 @@ do
[[ ${what[(w)6]:t} != ${what[(w)1]} ]] &&
run_help_orig_cmd=${what[(w)1]} run-help ${what[(w)6]:t}
;;
- (*( is a * function))
- case ${what[(w)1]} in
- (comp*) man zshcompsys;;
- (zf*) man zshftpsys;;
- (run-help) man zshcontrib;;
- (*) builtin functions ${what[(w)1]} | ${=PAGER:-more};;
- esac;;
(*( is a * builtin))
case ${what[(w)1]} in
(compctl) man zshcompctl;;
@@ -92,26 +96,73 @@ do
(*( is a reserved word))
man zshmisc
;;
- (*)
- if ((! didman++))
- then
- if whence "run-help-$1:t" >/dev/null
- then
- local cmd_args
- 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]}"
- else
- POSIXLY_CORRECT=1 man $@:t
- fi
- fi
- ;;
+ ( comp*( is a* function)* )
+ man zshcompsys
+ ;;
+ ( zf*( is a* function)* )
+ man zshzftpsys
+ ;;
+ ( ((run-help*|which-command) is a* function)* )
+ man zshcontrib
+ ;;
+ ( * )
+ if (( ! didman++ )); then
+ local cmd_args help
+ builtin read -zr cmd_args # Get the original command line.
+ builtin print -z "$cmd_args" # Put it back on the buffer stack.
+
+ # Retain only subcommands & options.
+ cmd_args=( ${${(z)cmd_args}[(r)${run_help_orig_cmd:-$1},(r)(-|--)]} )
+ (( $#cmd_args )) &&
+ shift cmd_args
+
+ whence "run-help-$1:t" >/dev/null &&
+ eval "run-help-$1:t ${(@q)cmd_args}" &&
+ return
+
+ # For safety, skip all option flags & anything that looks like a file.
+ while [[ $#cmd_args -gt 0 &&
+ ( -e $~cmd_args[1] || $cmd_args[1] == [-+]* ) ]]; do
+ shift cmd_args
+ done
+
+ # Try if we're dealing with a subcommand and can get help on that.
+ if [[ -n $cmd_args[1] ]]; then
+ # The order in which we try these matters.
+ for help in "$cmd_args[1] "{--help,-h} {-h,--help}" $cmd_args[1]"; do
+ .run-help.eval "$1:t $help" &&
+ return
+ done
+ fi
+
+ # Try the man page.
+ POSIXLY_CORRECT=1 man $1:t 2>/dev/null &&
+ return
+
+ # Try getting help on the main command.
+ for help in -h --help; do
+ .run-help.eval "$1:t $help" &&
+ return
+ done
+
+ if [[ $what = *( is a* function)* ]]; then
+ local func=$what[(w)1]
+
+ # Try to show function source from file, because parsed functions
+ # don't contain comments.
+ autoload +X -Uz $func
+ [[ -n $functions_source[$func] ]] &&
+ ${=PAGER:-more} -- $functions_source[$func] &&
+ return
+
+ builtin functions $func | ${=PAGER:-more} &&
+ return
+ fi
+
+ print -u2 "run-help: no help found for '$what[(w)1]'"
+ return 1
+ fi
+ ;;
esac
if ((i < $#places && ! didman))
then
@@ -124,3 +175,6 @@ done
} always {
unset run_help_orig_cmd
}
+}
+
+run-help "$@"
--
2.31.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [RFC][PATCH] Try calling command with help flags in run-help
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-02 20:58 ` Let run-help filter cmd_args before calling run-help-<command> " Marlon Richert
0 siblings, 2 replies; 20+ messages in thread
From: Bart Schaefer @ 2021-05-25 20:57 UTC (permalink / raw)
To: Marlon Richert; +Cc: Zsh hackers list
On Tue, May 25, 2021 at 1:49 PM Marlon Richert <marlon.richert@gmail.com> wrote:
>
> When there isn't a man page, try calling the command with --help or -h.
This is not a good idea, because we can't predict what will happen if
a given command does not support those options, or interprets them
differently.
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH] Let run-help try to show function source from file (was Re: [RFC][PATCH] Try calling command with help flags in run-help)
2021-05-25 20:57 ` Bart Schaefer
@ 2021-06-02 18:26 ` Marlon Richert
2021-06-20 21:23 ` Lawrence Velázquez
2021-06-02 20:58 ` Let run-help filter cmd_args before calling run-help-<command> " Marlon Richert
1 sibling, 1 reply; 20+ messages in thread
From: Marlon Richert @ 2021-06-02 18:26 UTC (permalink / raw)
To: Bart Schaefer, Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 456 bytes --]
Here's part of workers 48926 as a separate patch.
On Tue, May 25, 2021 at 11:57 PM Bart Schaefer
<schaefer@brasslantern.com> wrote:
>
> On Tue, May 25, 2021 at 1:49 PM Marlon Richert <marlon.richert@gmail.com> wrote:
> >
> > When there isn't a man page, try calling the command with --help or -h.
>
> This is not a good idea, because we can't predict what will happen if
> a given command does not support those options, or interprets them
> differently.
[-- Attachment #2: 0001-Let-run-help-try-to-show-function-source-from-file.txt --]
[-- Type: text/plain, Size: 1276 bytes --]
From 4cbb4642bb9c4f06fbc6729ecf2995e498cf3d61 Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlon.richert@gmail.com>
Date: Wed, 2 Jun 2021 21:22:59 +0300
Subject: [PATCH] Let run-help try to show function source from file
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
…because parsed functions don't contain comments.
---
Functions/Misc/run-help | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help
index e351dd6a6..b5e692198 100644
--- a/Functions/Misc/run-help
+++ b/Functions/Misc/run-help
@@ -69,7 +69,18 @@ do
(comp*) man zshcompsys;;
(zf*) man zshftpsys;;
(run-help) man zshcontrib;;
- (*) builtin functions ${what[(w)1]} | ${=PAGER:-more};;
+ ( * )
+ local func=$what[(w)1]
+
+ # Try to show function source from file, because parsed functions
+ # don't contain comments.
+ autoload +X -Uz $func
+ if [[ -n $functions_source[$func] ]]; then
+ ${=PAGER:-more} -- $functions_source[$func]
+ else
+ builtin functions $func | ${=PAGER:-more}
+ fi
+ ;;
esac;;
(*( is a * builtin))
case ${what[(w)1]} in
--
2.30.1 (Apple Git-130)
^ permalink raw reply [flat|nested] 20+ messages in thread
* Let run-help filter cmd_args before calling run-help-<command> (was Re: [RFC][PATCH] Try calling command with help flags in run-help)
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-02 20:58 ` Marlon Richert
2021-06-03 4:34 ` Bart Schaefer
1 sibling, 1 reply; 20+ messages in thread
From: Marlon Richert @ 2021-06-02 20:58 UTC (permalink / raw)
To: Bart Schaefer, Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 468 bytes --]
And here's another part of workers 48926 as a separate patch.
On Tue, May 25, 2021 at 11:57 PM Bart Schaefer
<schaefer@brasslantern.com> wrote:
>
> On Tue, May 25, 2021 at 1:49 PM Marlon Richert <marlon.richert@gmail.com> wrote:
> >
> > When there isn't a man page, try calling the command with --help or -h.
>
> This is not a good idea, because we can't predict what will happen if
> a given command does not support those options, or interprets them
> differently.
[-- Attachment #2: 0001-Let-run-help-filter-cmd_args-before-calling-run-help.txt --]
[-- Type: text/plain, Size: 3646 bytes --]
From 29d2c303c43039a333e9ad3a5c495f33af85d955 Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlon.richert@gmail.com>
Date: Wed, 2 Jun 2021 22:58:42 +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 | 27 +++++++++++++++++++++------
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, 24 insertions(+), 17 deletions(-)
diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help
index e351dd6a6..19f51a7f8 100644
--- a/Functions/Misc/run-help
+++ b/Functions/Misc/run-help
@@ -101,12 +101,27 @@ 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 environment assignments, etc.
+ while [[ $cmd_args[1] != ${run_help_orig_cmd:-$1} ]]; do
+ shift cmd_args ||
+ return 1
+ done
+
+ # Discard the command itself.
+ shift cmd_args
+
+ # Discard the first -, -- or ; and everything after it.
+ shift -p (( $#cmd_args + 1 - cmd_args[(i)(-|--|;)] )) cmd_args
+
+ # Discard options, parameter assignments & paths.
+ while [[ $#cmd_args[@] -gt 0 &&
+ ( $cmd_args[1] == ([-+]|*=*|*/*|~*) ||
+ -e ${(e)~cmd_args[1]} ) ]]; do
+ shift cmd_args
+ done
+
+ 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)
^ permalink raw reply [flat|nested] 20+ messages in thread
* 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)
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
0 siblings, 2 replies; 20+ messages in thread
From: Bart Schaefer @ 2021-06-03 4:34 UTC (permalink / raw)
To: Marlon Richert; +Cc: Zsh hackers list
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
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".
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", some commands that have git-style sub-commands, or .
^ permalink raw reply [flat|nested] 20+ messages in thread
* 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)
2021-06-03 4:34 ` Bart Schaefer
@ 2021-06-03 4:38 ` Bart Schaefer
2021-06-03 21:26 ` Marlon Richert
1 sibling, 0 replies; 20+ messages in thread
From: Bart Schaefer @ 2021-06-03 4:38 UTC (permalink / raw)
To: Marlon Richert; +Cc: Zsh hackers list
On Wed, Jun 2, 2021 at 9:34 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> and "sudo", some commands that have git-style sub-commands, or .
A keyboard shortcut or something sent that in the middle of an edit.
Should read:
and "sudo", or some commands that have git-style sub-commands.
^ permalink raw reply [flat|nested] 20+ messages in thread
* 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)
2021-06-03 4:34 ` Bart Schaefer
2021-06-03 4:38 ` Bart Schaefer
@ 2021-06-03 21:26 ` Marlon Richert
2021-06-03 21:45 ` Lawrence Velázquez
2021-06-03 23:33 ` Bart Schaefer
1 sibling, 2 replies; 20+ messages in thread
From: Marlon Richert @ 2021-06-03 21:26 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh hackers list
[-- 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)
^ permalink raw reply [flat|nested] 20+ messages in thread
* 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)
2021-06-03 21:26 ` Marlon Richert
@ 2021-06-03 21:45 ` Lawrence Velázquez
2021-06-03 21:52 ` Bart Schaefer
2021-06-03 23:33 ` Bart Schaefer
1 sibling, 1 reply; 20+ messages in thread
From: Lawrence Velázquez @ 2021-06-03 21:45 UTC (permalink / raw)
To: Marlon Richert, Bart Schaefer; +Cc: zsh-workers
On Thu, Jun 3, 2021, at 5:26 PM, Marlon Richert wrote:
> On Thu, Jun 3, 2021 at 7:34 AM Bart Schaefer <schaefer@brasslantern.com> wrote:
> > 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).
Same for me, on the 5.8 release.
> > 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'.
This already works correctly for me on the 5.8 release, but I don't
have any zsh or git aliases configured.
--
vq
^ permalink raw reply [flat|nested] 20+ messages in thread
* 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)
2021-06-03 21:45 ` Lawrence Velázquez
@ 2021-06-03 21:52 ` Bart Schaefer
2021-06-03 22:00 ` Lawrence Velázquez
0 siblings, 1 reply; 20+ messages in thread
From: Bart Schaefer @ 2021-06-03 21:52 UTC (permalink / raw)
To: Lawrence Velázquez; +Cc: Marlon Richert, Zsh hackers list
On Thu, Jun 3, 2021 at 2:46 PM Lawrence Velázquez <larryv@zsh.org> wrote:
>
> On Thu, Jun 3, 2021, at 5:26 PM, Marlon Richert wrote:
> > On Thu, Jun 3, 2021 at 7:34 AM Bart Schaefer <schaefer@brasslantern.com> wrote:
> > > 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).
>
> Same for me, on the 5.8 release.
The run-help-ssh function isn't actually in the distribution anywhere
except as an example in the doc. You have to copy-paste it into your
shell before attempting run-help.
^ permalink raw reply [flat|nested] 20+ messages in thread
* 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)
2021-06-03 21:52 ` Bart Schaefer
@ 2021-06-03 22:00 ` Lawrence Velázquez
0 siblings, 0 replies; 20+ messages in thread
From: Lawrence Velázquez @ 2021-06-03 22:00 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Marlon Richert, zsh-workers
On Thu, Jun 3, 2021, at 5:52 PM, Bart Schaefer wrote:
> The run-help-ssh function isn't actually in the distribution anywhere
> except as an example in the doc. You have to copy-paste it into your
> shell before attempting run-help.
Oops, I missed that you're talking about run-help-X, which I didn't
know about. Carry on!
--
vq
^ permalink raw reply [flat|nested] 20+ messages in thread
* 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)
2021-06-03 21:26 ` Marlon Richert
2021-06-03 21:45 ` Lawrence Velázquez
@ 2021-06-03 23:33 ` Bart Schaefer
2021-06-05 19:15 ` Marlon Richert
1 sibling, 1 reply; 20+ messages in thread
From: Bart Schaefer @ 2021-06-03 23:33 UTC (permalink / raw)
To: Marlon Richert; +Cc: Zsh hackers list
On Thu, Jun 3, 2021 at 2:27 PM Marlon Richert <marlon.richert@gmail.com> wrote:
>
> On Thu, Jun 3, 2021 at 7:34 AM Bart Schaefer <schaefer@brasslantern.com> wrote:
> > 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).
As mentioned elsewhere, you do have to manually load run-help-ssh into
your test shell, it is not an autoloadable file.
> My patch actually fixes an annoying case with 'run-help git'. Try
> pressing ^[h on, for example, 'git -C /path/to/zsh log'.
This works for me, with or without your patch, using the git
completion in the current repository head. Are you sure you're
loading functions from the right path?
> Anyway, here's a new version of my patch. Let me know what you think.
I don't see any obvious problems with it but I don't know how to
construct a test case for any of the helpers you've edited. It would
be nice to know that this does not break the un-edited versions of
those helpers, because if those changes are required rather than just
redundant code removal, other helpers in the wild would also require
editing.
^ permalink raw reply [flat|nested] 20+ messages in thread
* 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)
2021-06-03 23:33 ` Bart Schaefer
@ 2021-06-05 19:15 ` Marlon Richert
2021-06-20 18:01 ` Lawrence Velázquez
0 siblings, 1 reply; 20+ messages in thread
From: Marlon Richert @ 2021-06-05 19:15 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh hackers list
[-- Attachment #1.1: Type: text/plain, Size: 768 bytes --]
On Fri, Jun 4, 2021 at 2:33 AM Bart Schaefer <schaefer@brasslantern.com>
wrote:
> > Anyway, here's a new version of my patch. Let me know what you think.
>
> I don't see any obvious problems with it but I don't know how to
> construct a test case for any of the helpers you've edited. It would
> be nice to know that this does not break the un-edited versions of
> those helpers, because if those changes are required rather than just
> redundant code removal, other helpers in the wild would also require
> editing.
>
New patch here with test cases, plus a rewrite of run-help-git. All the
tests succeed for both the new and old versions of the run-help-* functions
(except for the old run-help-git, because the new run-help-git uses `git
help` instead of `man`).
[-- Attachment #1.2: Type: text/html, Size: 1111 bytes --]
[-- Attachment #2: 0001-Let-run-help-filter-cmd_args-before-calling-run-help.txt --]
[-- Type: text/plain, Size: 5998 bytes --]
From 21257c087fdf8896cc7362ed432a76de7f4a1fff Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlon.richert@gmail.com>
Date: Sat, 5 Jun 2021 22:06:50 +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-git | 10 +---
Functions/Misc/run-help-ip | 4 --
Functions/Misc/run-help-p4 | 2 +-
Functions/Misc/run-help-svk | 2 +-
Functions/Misc/run-help-svn | 2 +-
Test/Z03run-help.ztst | 103 ++++++++++++++++++++++++++++++++++
8 files changed, 116 insertions(+), 26 deletions(-)
create mode 100644 Test/Z03run-help.ztst
diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help
index e351dd6a6..d52c1b032 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-git b/Functions/Misc/run-help-git
index ce94d0d02..a841f89d6 100644
--- a/Functions/Misc/run-help-git
+++ b/Functions/Misc/run-help-git
@@ -1,9 +1 @@
-if [ $# -eq 0 ]; then
- man git
-else
- local al
- if al=$(git config --get "alias.$1"); then
- 1=${al%% *}
- fi
- man git-$1
-fi
+git help ${1:-git}
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}
diff --git a/Test/Z03run-help.ztst b/Test/Z03run-help.ztst
new file mode 100644
index 000000000..1f280fea7
--- /dev/null
+++ b/Test/Z03run-help.ztst
@@ -0,0 +1,103 @@
+%prep
+ PAGER=cat
+ unalias run-help
+ autoload +X -Uz $PWD/../Functions/Misc/run-help*
+ builtin() {
+ case "$1 $2" in
+ ( 'getln cmd_args' )
+ cmd_args="$BUFFER_STACK"
+ ;;
+ ( 'print -z' )
+ ;;
+ ( 'whence -va' )
+ print -l "$3 is WHENCE:{$3}"
+ ;;
+ ( * )
+ eval $@
+ ;;
+ esac
+ }
+ man() {
+ [[ $1 == -w && -n $NO_SUBCMD_MANUALS ]] &&
+ return 1
+ print "MAN:{${(qq)@}}"
+ }
+ git svn () {
+ print "${(U)0}:{${(qq)@}}"
+ }
+
+
+%test
+
+ BUFFER_STACK='btrfs --help'
+ run-help btrfs
+0:btrfs with option flag, no subcmd
+>btrfs is WHENCE:{btrfs}
+>MAN:{'btrfs'}
+
+ BUFFER_STACK='btrfs subvolume snapshot –r /btrfs/SV1 /btrfs/SV1-rosnap'
+ run-help btrfs
+0:btrfs with subcmd
+>btrfs is WHENCE:{btrfs}
+>MAN:{'btrfs-subvolume'}
+
+ BUFFER_STACK="sudo $BUFFER_STACK"
+ run-help btrfs
+0:sudo btrfs with subcmd
+>btrfs is WHENCE:{btrfs}
+>MAN:{'btrfs-subvolume'}
+
+ BUFFER_STACK='ip addr add 192.168.50.5 dev eth1'
+ run-help ip
+0:ip with subcmd
+>ip is WHENCE:{ip}
+>MAN:{'ip-address'}
+
+ NO_SUBCMD_MANUALS=1
+ run-help ip
+ unset NO_SUBCMD_MANUALS
+0:ip with subcmd, but no subcmd manuals
+>ip is WHENCE:{ip}
+>MAN:{'ip'}
+
+ BUFFER_STACK='ip -s -s link ls up'
+ run-help ip
+0:ip with options and subcmd
+>ip is WHENCE:{ip}
+>MAN:{'ip-link'}
+
+ BUFFER_STACK="sudo $BUFFER_STACK"
+ run-help ip
+0:sudo ip with options and subcmd
+>ip is WHENCE:{ip}
+>MAN:{'ip-link'}
+
+ BUFFER_STACK='svn -vq'
+ run-help svn
+0:svn with options
+>svn is WHENCE:{svn}
+>SVN:{'help'}
+
+ BUFFER_STACK+=' commit -m "log messages"'
+ run-help svn
+0:svn with options and subcmd
+>svn is WHENCE:{svn}
+>SVN:{'help' 'commit'}
+
+ BUFFER_STACK='git --exec-path'
+0:git with option
+>git is WHENCE:{git}
+>GIT:{'help' 'git'}
+
+ BUFFER_STACK='git -C $PWD/.. difftool --no-prompt --tool opendiff --dir-diff'
+0:git with option, file & subcmd
+>git is WHENCE:{git}
+>GIT:{'help' 'difftool'}
+
+ BUFFER_STACK='git -c http.proxy=someproxy clone https://github.com/user/repo.git'
+0:git with option, assignment & subcmd
+>git is WHENCE:{git}
+>GIT:{'help' 'clone'}
+
+
+%clean
--
2.30.1 (Apple Git-130)
^ permalink raw reply [flat|nested] 20+ messages in thread
* 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)
2021-06-05 19:15 ` Marlon Richert
@ 2021-06-20 18:01 ` Lawrence Velázquez
2021-07-18 18:45 ` Lawrence Velázquez
0 siblings, 1 reply; 20+ messages in thread
From: Lawrence Velázquez @ 2021-06-20 18:01 UTC (permalink / raw)
To: zsh-workers; +Cc: Marlon Richert
On Sat, Jun 5, 2021, at 3:15 PM, Marlon Richert wrote:
> New patch here with test cases, plus a rewrite of run-help-git. All the
> tests succeed for both the new and old versions of the run-help-*
> functions (except for the old run-help-git, because the new
> run-help-git uses `git help` instead of `man`).
>
> Attachments:
> * 0001-Let-run-help-filter-cmd_args-before-calling-run-help.txt
bump
--
vq
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Let run-help try to show function source from file (was Re: [RFC][PATCH] Try calling command with help flags in run-help)
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
0 siblings, 2 replies; 20+ messages in thread
From: Lawrence Velázquez @ 2021-06-20 21:23 UTC (permalink / raw)
To: zsh-workers; +Cc: Marlon Richert
On Wed, Jun 2, 2021, at 2:26 PM, Marlon Richert wrote:
> Here's part of workers 48926 as a separate patch.
>
> Attachments:
> * 0001-Let-run-help-try-to-show-function-source-from-file.txt
ping, needs review
--
vq
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Let run-help try to show function source from file (was Re: [RFC][PATCH] Try calling command with help flags in run-help)
2021-06-20 21:23 ` Lawrence Velázquez
@ 2021-07-18 18:38 ` Lawrence Velázquez
2021-07-28 2:03 ` Bart Schaefer
1 sibling, 0 replies; 20+ messages in thread
From: Lawrence Velázquez @ 2021-07-18 18:38 UTC (permalink / raw)
To: zsh-workers; +Cc: Marlon Richert
On Sun, Jun 20, 2021, at 5:23 PM, Lawrence Velázquez wrote:
> On Wed, Jun 2, 2021, at 2:26 PM, Marlon Richert wrote:
> > Here's part of workers 48926 as a separate patch.
> >
> > Attachments:
> > * 0001-Let-run-help-try-to-show-function-source-from-file.txt
>
> ping, needs review
ping redux
--
vq
^ permalink raw reply [flat|nested] 20+ messages in thread
* 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)
2021-06-20 18:01 ` Lawrence Velázquez
@ 2021-07-18 18:45 ` Lawrence Velázquez
2021-07-28 17:58 ` Bart Schaefer
0 siblings, 1 reply; 20+ messages in thread
From: Lawrence Velázquez @ 2021-07-18 18:45 UTC (permalink / raw)
To: zsh-workers; +Cc: Marlon Richert
On Sun, Jun 20, 2021, at 2:01 PM, Lawrence Velázquez wrote:
> On Sat, Jun 5, 2021, at 3:15 PM, Marlon Richert wrote:
> > New patch here with test cases, plus a rewrite of run-help-git. All the
> > tests succeed for both the new and old versions of the run-help-*
> > functions (except for the old run-help-git, because the new
> > run-help-git uses `git help` instead of `man`).
> >
> > Attachments:
> > * 0001-Let-run-help-filter-cmd_args-before-calling-run-help.txt
>
> bump
bump bump
--
vq
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Let run-help try to show function source from file (was Re: [RFC][PATCH] Try calling command with help flags in run-help)
2021-06-20 21:23 ` Lawrence Velázquez
2021-07-18 18:38 ` Lawrence Velázquez
@ 2021-07-28 2:03 ` Bart Schaefer
1 sibling, 0 replies; 20+ messages in thread
From: Bart Schaefer @ 2021-07-28 2:03 UTC (permalink / raw)
To: Lawrence Velázquez; +Cc: Zsh hackers list, Marlon Richert
On Sun, Jun 20, 2021 at 2:24 PM Lawrence Velázquez <larryv@zsh.org> wrote:
>
> On Wed, Jun 2, 2021, at 2:26 PM, Marlon Richert wrote:
> > Here's part of workers 48926 as a separate patch.
> >
> > Attachments:
> > * 0001-Let-run-help-try-to-show-function-source-from-file.txt
>
> ping, needs review
Finally looked a little more closely at this.
I don't think we can allow it to unconditionally run
autoload +X -Uz $func
because for example it's always possible that $func should be
autoloaded with -k instead. Further, even if we grab the correct
autoload flags, it's possible that loading the function will have some
side-effects, or that loading it with +X will omit some necessary
side-effects.
Also, if the function was loaded from a zcompile file, displaying
$functions_source[$func] with the pager will either fail or be a mess.
There's also the minor point that if the function came from a file
containing multiple other functions, you get way more than you asked
for.
^ permalink raw reply [flat|nested] 20+ messages in thread
* 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)
2021-07-18 18:45 ` Lawrence Velázquez
@ 2021-07-28 17:58 ` Bart Schaefer
2021-07-29 12:11 ` Marlon Richert
0 siblings, 1 reply; 20+ messages in thread
From: Bart Schaefer @ 2021-07-28 17:58 UTC (permalink / raw)
To: Lawrence Velázquez; +Cc: Zsh hackers list, Marlon Richert
On Sun, Jul 18, 2021 at 11:46 AM Lawrence Velázquez <larryv@zsh.org> wrote:
>
> On Sun, Jun 20, 2021, at 2:01 PM, Lawrence Velázquez wrote:
> > On Sat, Jun 5, 2021, at 3:15 PM, Marlon Richert wrote:
> > > New patch here with test cases, plus a rewrite of run-help-git. All the
> > > tests succeed for both the new and old versions of the run-help-*
> > > functions (except for the old run-help-git, because the new
> > > run-help-git uses `git help` instead of `man`).
> > >
> > > Attachments:
> > > * 0001-Let-run-help-filter-cmd_args-before-calling-run-help.txt
> >
> > bump
>
> bump bump
Nothing obviously wrong with the code patch, but one of the test cases
fails for me:
--- /tmp/zsh.ztst.50384/ztst.out 2021-07-28 10:56:06.301935368 -0700
+++ /tmp/zsh.ztst.50384/ztst.tout 2021-07-28 10:56:06.301935368 -0700
@@ -1,2 +0,0 @@
-git is WHENCE:{git}
-GIT:{'help' 'git'}
Test ./Z03run-help.ztst failed: output differs from expected as shown above for:
BUFFER_STACK='git --exec-path'
Was testing: git with option
./Z03run-help.ztst: test failed.
^ permalink raw reply [flat|nested] 20+ messages in thread
* 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)
2021-07-28 17:58 ` Bart Schaefer
@ 2021-07-29 12:11 ` Marlon Richert
2021-07-30 16:55 ` Bart Schaefer
0 siblings, 1 reply; 20+ messages in thread
From: Marlon Richert @ 2021-07-29 12:11 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Lawrence Velázquez, Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 1370 bytes --]
On Wed, Jul 28, 2021 at 8:58 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> On Sun, Jul 18, 2021 at 11:46 AM Lawrence Velázquez <larryv@zsh.org> wrote:
> >
> > On Sun, Jun 20, 2021, at 2:01 PM, Lawrence Velázquez wrote:
> > > On Sat, Jun 5, 2021, at 3:15 PM, Marlon Richert wrote:
> > > > New patch here with test cases, plus a rewrite of run-help-git. All the
> > > > tests succeed for both the new and old versions of the run-help-*
> > > > functions (except for the old run-help-git, because the new
> > > > run-help-git uses `git help` instead of `man`).
> > > >
> > > > Attachments:
> > > > * 0001-Let-run-help-filter-cmd_args-before-calling-run-help.txt
> > >
> > > bump
> >
> > bump bump
>
> Nothing obviously wrong with the code patch, but one of the test cases
> fails for me:
>
> --- /tmp/zsh.ztst.50384/ztst.out 2021-07-28 10:56:06.301935368 -0700
> +++ /tmp/zsh.ztst.50384/ztst.tout 2021-07-28 10:56:06.301935368 -0700
> @@ -1,2 +0,0 @@
> -git is WHENCE:{git}
> -GIT:{'help' 'git'}
> Test ./Z03run-help.ztst failed: output differs from expected as shown above for:
> BUFFER_STACK='git --exec-path'
> Was testing: git with option
> ./Z03run-help.ztst: test failed.
Looks like I somehow managed to omit some lines from the tests in the
patch. Here's a new patch, differing only in the `run-help git` tests:
[-- Attachment #2: 0001-Let-run-help-filter-cmd_args-before-calling-run-help.txt --]
[-- Type: text/plain, Size: 5907 bytes --]
From 673123be01b29518921a054aacdcaa4811285473 Mon Sep 17 00:00:00 2001
From: Marlon Richert <marlonrichert@users.noreply.github.com>
Date: Thu, 29 Jul 2021 15:08:11 +0300
Subject: [PATCH] Let run-help filter $cmd_args before calling
run-help-<command>
---
Functions/Misc/run-help | 15 +++--
Functions/Misc/run-help-btrfs | 4 --
Functions/Misc/run-help-git | 10 +---
Functions/Misc/run-help-ip | 4 --
Functions/Misc/run-help-p4 | 2 +-
Functions/Misc/run-help-svk | 2 +-
Functions/Misc/run-help-svn | 2 +-
Test/Z03run-help.ztst | 106 ++++++++++++++++++++++++++++++++++
8 files changed, 119 insertions(+), 26 deletions(-)
create mode 100644 Test/Z03run-help.ztst
diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help
index e351dd6a6..d52c1b032 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-git b/Functions/Misc/run-help-git
index ce94d0d02..a841f89d6 100644
--- a/Functions/Misc/run-help-git
+++ b/Functions/Misc/run-help-git
@@ -1,9 +1 @@
-if [ $# -eq 0 ]; then
- man git
-else
- local al
- if al=$(git config --get "alias.$1"); then
- 1=${al%% *}
- fi
- man git-$1
-fi
+git help ${1:-git}
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}
diff --git a/Test/Z03run-help.ztst b/Test/Z03run-help.ztst
new file mode 100644
index 000000000..2bb3bceed
--- /dev/null
+++ b/Test/Z03run-help.ztst
@@ -0,0 +1,106 @@
+%prep
+ PAGER=cat
+ unalias run-help
+ autoload +X -Uz $PWD/../Functions/Misc/run-help*
+ builtin() {
+ case "$1 $2" in
+ ( 'getln cmd_args' )
+ cmd_args="$BUFFER_STACK"
+ ;;
+ ( 'print -z' )
+ ;;
+ ( 'whence -va' )
+ print -l "$3 is WHENCE:{$3}"
+ ;;
+ ( * )
+ eval $@
+ ;;
+ esac
+ }
+ man() {
+ [[ $1 == -w && -n $NO_SUBCMD_MANUALS ]] &&
+ return 1
+ print "MAN:{${(qq)@}}"
+ }
+ git svn () {
+ print "${(U)0}:{${(qq)@}}"
+ }
+
+
+%test
+
+ BUFFER_STACK='btrfs --help'
+ run-help btrfs
+0:btrfs with option flag, no subcmd
+>btrfs is WHENCE:{btrfs}
+>MAN:{'btrfs'}
+
+ BUFFER_STACK='btrfs subvolume snapshot –r /btrfs/SV1 /btrfs/SV1-rosnap'
+ run-help btrfs
+0:btrfs with subcmd
+>btrfs is WHENCE:{btrfs}
+>MAN:{'btrfs-subvolume'}
+
+ BUFFER_STACK="sudo $BUFFER_STACK"
+ run-help btrfs
+0:sudo btrfs with subcmd
+>btrfs is WHENCE:{btrfs}
+>MAN:{'btrfs-subvolume'}
+
+ BUFFER_STACK='ip addr add 192.168.50.5 dev eth1'
+ run-help ip
+0:ip with subcmd
+>ip is WHENCE:{ip}
+>MAN:{'ip-address'}
+
+ NO_SUBCMD_MANUALS=1
+ run-help ip
+ unset NO_SUBCMD_MANUALS
+0:ip with subcmd, but no subcmd manuals
+>ip is WHENCE:{ip}
+>MAN:{'ip'}
+
+ BUFFER_STACK='ip -s -s link ls up'
+ run-help ip
+0:ip with options and subcmd
+>ip is WHENCE:{ip}
+>MAN:{'ip-link'}
+
+ BUFFER_STACK="sudo $BUFFER_STACK"
+ run-help ip
+0:sudo ip with options and subcmd
+>ip is WHENCE:{ip}
+>MAN:{'ip-link'}
+
+ BUFFER_STACK='svn -vq'
+ run-help svn
+0:svn with options
+>svn is WHENCE:{svn}
+>SVN:{'help'}
+
+ BUFFER_STACK+=' commit -m "log messages"'
+ run-help svn
+0:svn with options and subcmd
+>svn is WHENCE:{svn}
+>SVN:{'help' 'commit'}
+
+ BUFFER_STACK='git --exec-path'
+ run-help git
+0:git with option
+>git is WHENCE:{git}
+>GIT:{'help' 'git'}
+
+ BUFFER_STACK='git -C $PWD/.. difftool --no-prompt --tool opendiff --dir-diff'
+ run-help git
+0:git with option, file & subcmd
+>git is WHENCE:{git}
+>GIT:{'help' 'difftool'}
+
+ BUFFER_STACK='git -c http.proxy=someproxy clone https://github.com/user/repo.git'
+ run-help git
+0:git with option, assignment & subcmd
+>git is WHENCE:{git}
+>GIT:{'help' 'clone'}
+
+
+%clean
--
2.30.1 (Apple Git-130)
^ permalink raw reply [flat|nested] 20+ messages in thread
* 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)
2021-07-29 12:11 ` Marlon Richert
@ 2021-07-30 16:55 ` Bart Schaefer
0 siblings, 0 replies; 20+ messages in thread
From: Bart Schaefer @ 2021-07-30 16:55 UTC (permalink / raw)
To: Marlon Richert; +Cc: Lawrence Velázquez, Zsh hackers list
This one appears clean. Thanks.
On Thu, Jul 29, 2021 at 5:11 AM Marlon Richert <marlon.richert@gmail.com> wrote:
>
> On Wed, Jul 28, 2021 at 8:58 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
> >
> > On Sun, Jul 18, 2021 at 11:46 AM Lawrence Velázquez <larryv@zsh.org> wrote:
> > >
> > > On Sun, Jun 20, 2021, at 2:01 PM, Lawrence Velázquez wrote:
> > > > On Sat, Jun 5, 2021, at 3:15 PM, Marlon Richert wrote:
> > > > > New patch here with test cases, plus a rewrite of run-help-git. All the
> > > > > tests succeed for both the new and old versions of the run-help-*
> > > > > functions (except for the old run-help-git, because the new
> > > > > run-help-git uses `git help` instead of `man`).
> > > > >
> > > > > Attachments:
> > > > > * 0001-Let-run-help-filter-cmd_args-before-calling-run-help.txt
> > > >
> > > > bump
> > >
> > > bump bump
> >
> > Nothing obviously wrong with the code patch, but one of the test cases
> > fails for me:
> >
> > --- /tmp/zsh.ztst.50384/ztst.out 2021-07-28 10:56:06.301935368 -0700
> > +++ /tmp/zsh.ztst.50384/ztst.tout 2021-07-28 10:56:06.301935368 -0700
> > @@ -1,2 +0,0 @@
> > -git is WHENCE:{git}
> > -GIT:{'help' 'git'}
> > Test ./Z03run-help.ztst failed: output differs from expected as shown above for:
> > BUFFER_STACK='git --exec-path'
> > Was testing: git with option
> > ./Z03run-help.ztst: test failed.
>
> Looks like I somehow managed to omit some lines from the tests in the
> patch. Here's a new patch, differing only in the `run-help git` tests:
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2021-07-30 16:56 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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
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).