zsh-workers
 help / color / mirror / code / Atom feed
* Re: [PATCH] run-help: ugly workaround for run-help-$X with alias for $X
@ 2009-12-14 11:40 Jörg Sommer
  2009-12-14 13:42 ` Peter Stephenson
  0 siblings, 1 reply; 9+ messages in thread
From: Jörg Sommer @ 2009-12-14 11:40 UTC (permalink / raw)
  To: zsh-workers

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

Hi Peter,

Peter Stephenson <pws@csr.com> wrote:
> Index: Functions/Misc/run-help
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Functions/Misc/run-help,v
> retrieving revision 1.16
> diff -u -r1.16 run-help
> --- Functions/Misc/run-help	5 Jun 2009 11:18:01 -0000	1.16
> +++ Functions/Misc/run-help	10 Dec 2009 09:48:44 -0000
> @@ -49,6 +49,7 @@
>    noalias=1
>  fi
>  
> +{
>  while ((i++ < $#places))
>  do
>      what=$places[$i]
> @@ -56,7 +57,8 @@
>      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}

> +} always {
> +  unset run_help_orig_cmd
> +}

Why do you need the unset here? In Posix shell an expression “VAR=xy
cmd” exports the variable VAR only to the command cmd, but doesn't export
or set it in the current environment. I zsh different here?

Bye, Jörg.
-- 
IRC: Der [Prof. Andreas Pfitzmann, TU Dresden] hat gerade vorgeschlagen, sie
  sollen doch statt Trojanern die elektromagnetische Abstrahlung nutzen. Das
  sei nicht massenfähig, ginge ohne Eingriff ins System, sei zielgerichtet,
  und, der Hammer, das funktioniere ja bei Wahlcomputern schon sehr gut.

[-- Attachment #2: Digital signature http://en.wikipedia.org/wiki/OpenPGP --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread
* [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
  0 siblings, 1 reply; 9+ 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] 9+ messages in thread

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

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-14 11:40 [PATCH] run-help: ugly workaround for run-help-$X with alias for $X Jörg Sommer
2009-12-14 13:42 ` Peter Stephenson
2009-12-14 15:50   ` Bart Schaefer
2009-12-14 16:38     ` Andrey Borzenkov
2009-12-14 17:01       ` Bart Schaefer
2009-12-16 10:57     ` Peter Stephenson
2009-12-18 13:51       ` Jörg Sommer
  -- strict thread matches above, loose matches on Subject: below --
2009-12-07  0:57 Jörg Sommer
2009-12-10  9:49 ` Peter Stephenson

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