zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@zsh.org
Cc: "Jörg Sommer" <joerg@alea.gnuu.de>
Subject: Re: [PATCH] run-help: ugly workaround for run-help-$X with alias for $X
Date: Thu, 10 Dec 2009 09:49:20 +0000	[thread overview]
Message-ID: <20091210094920.19aca3ce@news01> (raw)
In-Reply-To: <a355a85f3bdb0aac910702825eeb0b302ba155a9.1260147415.git.joerg@alea.gnuu.de>

On Mon,  7 Dec 2009 01:57:10 +0100
Jörg Sommer <joerg@alea.gnuu.de> wrote:
> 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.

I meant to post this slightly tidied up version (it's basically the
same logic) but forgot.

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}
 	;;
     (*( is a * function))
 	case ${what[(w)1]} in
@@ -96,9 +98,9 @@
 		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 || return 1
 		done
 		eval "run-help-$1:t ${(q@)cmd_args[2,-1]}"
 	    else
@@ -115,3 +117,6 @@
 	[[ $what == [qQ] ]] && break
     fi
 done
+} always {
+  unset run_help_orig_cmd
+}


-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


  reply	other threads:[~2009-12-10  9:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-07  0:57 Jörg Sommer
2009-12-10  9:49 ` Peter Stephenson [this message]
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
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091210094920.19aca3ce@news01 \
    --to=pws@csr.com \
    --cc=joerg@alea.gnuu.de \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).