From b2421219836d571b4f0ffa9568740922fa7005b8 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Wed, 10 May 2023 21:17:51 -0700 Subject: 51593: improve search for command name after skipping prefix assignments This is aimed mostly at use of run-help as a standalone function rather than as a widget. When run-help is invoked outside widget context, there's no source line to search for the original command name, so this attempts searching the arguments. --- ChangeLog | 5 +++++ Functions/Misc/run-help | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index e7e84a04b..956cb7eeb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2023-05-10 Bart Schaefer + + * 51593: Functions/Misc/run-help: improve search for original + command name after skipping prefix assignments + 2023-05-08 Jun-ichi Takimoto * 51692: Test/C02cond.ztst: do not skip tests for [[ -r file ]] diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help index 14d09bd65..462044b72 100644 --- a/Functions/Misc/run-help +++ b/Functions/Misc/run-help @@ -58,11 +58,11 @@ do 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} + 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} + run_help_orig_cmd=${what[(w)1]} run-help ${what[(w)6]:t} ${(z)${what[(w)7,-1]}} ;; (*( is a * function)) case ${what[(w)1]} in @@ -103,7 +103,7 @@ do cmd_args=( ${(z)${cmd_args:-"$*"}} ) # Discard the command itself & everything before it. - shift $cmd_args[(i)${run_help_orig_cmd:-$1}] cmd_args || + shift $cmd_args[(i)(${run_help_orig_cmd}|$1)] cmd_args 2>/dev/null || continue # Discard options, parameter assignments & paths. -- cgit 1.4.1