* 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
* Re: [PATCH] run-help: ugly workaround for run-help-$X with alias for $X
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
0 siblings, 1 reply; 9+ messages in thread
From: Peter Stephenson @ 2009-12-14 13:42 UTC (permalink / raw)
To: zsh-workers
=?iso-8859-1?Q?J=F6rg?= Sommer wrote:
> Why do you need the unset here?
It's the same "unset" that was in the original, just moved to a
position where it's guaranteed always to be executed.
--
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] run-help: ugly workaround for run-help-$X with alias for $X
2009-12-14 13:42 ` Peter Stephenson
@ 2009-12-14 15:50 ` Bart Schaefer
2009-12-14 16:38 ` Andrey Borzenkov
2009-12-16 10:57 ` Peter Stephenson
0 siblings, 2 replies; 9+ messages in thread
From: Bart Schaefer @ 2009-12-14 15:50 UTC (permalink / raw)
To: zsh-workers
On Dec 14, 1:42pm, Peter Stephenson wrote:
} Subject: Re: [PATCH] run-help: ugly workaround for run-help-$X with alias
}
} =?iso-8859-1?Q?J=F6rg?= Sommer wrote:
} > Why do you need the unset here?
}
} It's the same "unset" that was in the original, just moved to a
} position where it's guaranteed always to be executed.
Aside: I can't find the "var=value command ..." syntax anywhere in
the zsh manual. I was sure there was some mention of it, but it seems
to be in the category of "things all shells do" that zsh's manual does
not bother to reiterate.
That unset is probably there because older versions of zsh had some
bugs in the implementation of "var=value command ..." particularly in
the case where "command" is a function or builtin. This stemmed from
zsh's efforts to avoid forking when no external program was involved.
(I have the nagging feeling there are still some cases where the
parameter will intentionally remain set, but I can't recall what.)
However, the versions of zsh that have that problem will choke on the
"always" syntax, so there's no backwards compatibility benefit here.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] run-help: ugly workaround for run-help-$X with alias for $X
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
1 sibling, 1 reply; 9+ messages in thread
From: Andrey Borzenkov @ 2009-12-14 16:38 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: Text/Plain, Size: 793 bytes --]
On Monday 14 of December 2009 18:50:55 Bart Schaefer wrote:
>
> Aside: I can't find the "var=value command ..." syntax anywhere in
> the zsh manual. I was sure there was some mention of it,
As far as I can tell:
6.1 Simple Commands & Pipelines
===============================
A _simple command_ is a sequence of optional parameter assignments
followed by blank-separated words, with optional redirections
interspersed. The first word is the command to be executed, and the
remaining words, if any, are arguments to the command. If a command
name is given, the parameter assignments modify the environment of the
command when it is executed.
May be, what is missing - explicit statement that if no command name is
given, parameter assignments modify current shell.
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] run-help: ugly workaround for run-help-$X with alias for $X
2009-12-14 16:38 ` Andrey Borzenkov
@ 2009-12-14 17:01 ` Bart Schaefer
0 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2009-12-14 17:01 UTC (permalink / raw)
To: zsh-workers
On Dec 14, 7:38pm, Andrey Borzenkov wrote:
}
} > Aside: I can't find the "var=value command ..." syntax anywhere in
} > the zsh manual. I was sure there was some mention of it,
}
} As far as I can tell:
}
} 6.1 Simple Commands & Pipelines
} ===============================
}
} A _simple command_ is a sequence of optional parameter assignments
} followed by blank-separated words
Aha. I was searching for an actual example of the syntax, similar to
the grammar for complex commands that appears a couple sections later.
} May be, what is missing - explicit statement that if no command name is
} given, parameter assignments modify current shell.
The manual seems to distinguish between assignments (having no command)
and commands with optional assignments. I suppose you could say that a
simple command is a sequence of assignments, redirections, and words,
any of which are optional, but that's not how it currently is structured.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] run-help: ugly workaround for run-help-$X with alias for $X
2009-12-14 15:50 ` Bart Schaefer
2009-12-14 16:38 ` Andrey Borzenkov
@ 2009-12-16 10:57 ` Peter Stephenson
2009-12-18 13:51 ` Jörg Sommer
1 sibling, 1 reply; 9+ messages in thread
From: Peter Stephenson @ 2009-12-16 10:57 UTC (permalink / raw)
To: zsh-workers
On Mon, 14 Dec 2009 07:50:55 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> That unset is probably there because older versions of zsh had some
> bugs in the implementation of "var=value command ..." particularly in
> the case where "command" is a function or builtin. This stemmed from
> zsh's efforts to avoid forking when no external program was involved.
Actually, it's here (from the diff -u)...
+ unset run_help_orig_cmd
eval "run-help-$1:t ${(qq@)cmd_args[2,-1]}"
... so maybe I've missed the point: it may have been to prevent
$run_help_orig_cmd being seen by run-help-<something>. However, that seems
unlikely since (i) there's no reason they'd be confused by it (ii) they
might even find it useful.
I'll (finally) commit what's there at the moment and see what happens.
--
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] run-help: ugly workaround for run-help-$X with alias for $X
2009-12-16 10:57 ` Peter Stephenson
@ 2009-12-18 13:51 ` Jörg Sommer
0 siblings, 0 replies; 9+ messages in thread
From: Jörg Sommer @ 2009-12-18 13:51 UTC (permalink / raw)
To: zsh-workers
Hello Peter,
Peter Stephenson <pws@csr.com> wrote:
> On Mon, 14 Dec 2009 07:50:55 -0800
> Bart Schaefer <schaefer@brasslantern.com> wrote:
>> That unset is probably there because older versions of zsh had some
>> bugs in the implementation of "var=value command ..." particularly in
>> the case where "command" is a function or builtin. This stemmed from
>> zsh's efforts to avoid forking when no external program was involved.
>
> Actually, it's here (from the diff -u)...
>
> + unset run_help_orig_cmd
> eval "run-help-$1:t ${(qq@)cmd_args[2,-1]}"
>
> ... so maybe I've missed the point: it may have been to prevent
> $run_help_orig_cmd being seen by run-help-<something>.
Yes, this was my intention. I would like to avoid somebody uses this,
because it's an hack and might^Wshould be removed in the future.
Bye, Jörg.
--
< Mr X.> jo: contact an admin to mount it for you
< jo> The admin is not, well how should I say it, he isn't very familiar with
the system. What should I tell my admin, what he should do?
< Mr X.> taking a sun solaris administration course.
^ 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
* Re: [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, 0 replies; 9+ messages in thread
From: Peter Stephenson @ 2009-12-10 9:49 UTC (permalink / raw)
To: zsh-workers; +Cc: Jörg Sommer
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
^ 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).