zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] run-help: ugly workaround for run-help-$X with alias for $X
@ 2009-12-07  0:57 Jörg Sommer
  2009-12-10  9:49 ` Peter Stephenson
  2009-12-16 11:59 ` run-help as a widget Peter Stephenson
  0 siblings, 2 replies; 6+ messages in thread
From: Jörg Sommer @ 2009-12-07  0:57 UTC (permalink / raw)
  To: zsh-workers; +Cc: Jörg Sommer

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


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

end of thread, other threads:[~2009-12-18 23:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-07  0:57 [PATCH] run-help: ugly workaround for run-help-$X with alias for $X Jörg Sommer
2009-12-10  9:49 ` Peter Stephenson
2009-12-16 11:59 ` run-help as a widget Peter Stephenson
2009-12-16 17:14   ` Greg Klanderman
2009-12-18 16:59   ` Jörg Sommer
2009-12-18 23:28     ` Mikael Magnusson

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