Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] run-help: ugly workaround for run-help-$X with alias for $X



If you're very lazy and define an alias for git, e.g. g, and have the
function run-help-git defined, run-help will fail to strip everything up
to the expanded command from the commandline. In the first call of
run-help, the alias g gets expanded to git and run-help is called for
git. But the test of the while loop will never succed, because the
commandline fetched with getln doesn't contain the expanded command git.
Hence everything gets shifted from the array cmd_args until shift cries
forever

run-help:shift:101: shift count must be <= $#

I know, this solution is a dirty hack, but it's quick. The better way is
to fix zsh to call run-help with the whole commandline where the alias
gets expanded and this commandline gets passed to the second run-help
call.
---
 Functions/Misc/run-help |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help
index 8e88089..a974664 100644
--- a/Functions/Misc/run-help
+++ b/Functions/Misc/run-help
@@ -56,7 +56,8 @@ do
     builtin print -r $what
     case $what in
     (*( is an alias)*)
-	[[ ${what[(w)6]:t} != ${what[(w)1]} ]] && run-help ${what[(w)6]:t}
+	[[ ${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
@@ -96,10 +97,11 @@ do
 		builtin print -z "$cmd_args"
 		cmd_args=( ${(z)cmd_args} )
 		# Discard environment assignments, etc.
-		while [[ $cmd_args[1] != $1 ]]
+		while [[ $cmd_args[1] != ${run_help_orig_cmd:-$1} ]]
 		do
-		    shift cmd_args
+		    shift cmd_args || exit 1
 		done
+		unset run_help_orig_cmd
 		eval "run-help-$1:t ${(qq@)cmd_args[2,-1]}"
 	    else
 		POSIXLY_CORRECT=1 man $@:t
-- 
1.6.5



Messages sorted by: Reverse Date, Date, Thread, Author