* [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
* Re: [PATCH] run-help: ugly workaround for run-help-$X with alias for $X
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
1 sibling, 0 replies; 6+ 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] 6+ messages in thread
* run-help as a widget
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 ` Peter Stephenson
2009-12-16 17:14 ` Greg Klanderman
2009-12-18 16:59 ` Jörg Sommer
1 sibling, 2 replies; 6+ messages in thread
From: Peter Stephenson @ 2009-12-16 11:59 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:
> 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've been using this for a while, it's perhaps time something along these
lines got included in Functions/Zle. I was a bit surprised to find I
hadn't.
With this it would be worth upgrading run-help and helpers to check if
there's already a full command line there, and to advance past precommand
modifiers. I thought I'd done some of this, too, but maybe not...
I might simply have been thinking of expansion of aliases.
By the way, note this quotes all buffer words:
ls foo; rm -rf ~<Esc>h
is safe even if it may not do quite what you actually want, which is quite
hard to guess. (But I didn't try it quite like that anyway...)
# run-help-widget
#
# This is a widget to replace the builtin widget run-help.
# It passes the entire command line to run-help. This is often
# more useful.
#
# Typical usage:
# zle -N run-help run-help-widget
local -a line
if is-at-least 4.3.10; then
line=(${(q-)${(z)BUFFER}})
else
line=(${(qq)${(z)BUFFER}})
fi
zle push-line
BUFFER="run-help ${line}"
zle accept-line
--
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] 6+ messages in thread
* Re: run-help as a widget
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
1 sibling, 0 replies; 6+ messages in thread
From: Greg Klanderman @ 2009-12-16 17:14 UTC (permalink / raw)
To: zsh-workers
>>>>> On December 16, 2009 Peter Stephenson <pws@csr.com> wrote:
> if is-at-least 4.3.10; then
> line=(${(q-)${(z)BUFFER}})
(q-) is not actually in 4.3.10; it was added a few days later.
greg
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: run-help as a widget
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
1 sibling, 1 reply; 6+ messages in thread
From: Jörg Sommer @ 2009-12-18 16:59 UTC (permalink / raw)
To: zsh-workers
Hallo Peter,
Peter Stephenson <pws@csr.com> wrote:
> On Mon, 7 Dec 2009 01:57:10 +0100
> Jörg Sommer <joerg@alea.gnuu.de> wrote:
>> 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've been using this for a while, it's perhaps time something along these
> lines got included in Functions/Zle. I was a bit surprised to find I
> hadn't.
>
> With this it would be worth upgrading run-help and helpers to check if
> there's already a full command line there, and to advance past precommand
> modifiers. I thought I'd done some of this, too, but maybe not...
> I might simply have been thinking of expansion of aliases.
>
> By the way, note this quotes all buffer words:
>
> ls foo; rm -rf ~<Esc>h
>
> is safe even if it may not do quite what you actually want, which is quite
> hard to guess.
Isn't it possible to get the position where <Esc>h was hit or the prefix
and the suffix of the command? I would like to get help for true in this
situation:
% for h in $hosts; do ssh $h true<Esc>h; done
Bye, Jörg.
--
Die am Lautesten reden, haben stets am wenigsten zu sagen.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: run-help as a widget
2009-12-18 16:59 ` Jörg Sommer
@ 2009-12-18 23:28 ` Mikael Magnusson
0 siblings, 0 replies; 6+ messages in thread
From: Mikael Magnusson @ 2009-12-18 23:28 UTC (permalink / raw)
To: Jörg Sommer; +Cc: zsh-workers
2009/12/18 Jörg Sommer <joerg@alea.gnuu.de>:
> Isn't it possible to get the position where <Esc>h was hit or the prefix
> and the suffix of the command? I would like to get help for true in this
> situation:
>
> % for h in $hosts; do ssh $h true<Esc>h; done
I had _split_shell_arguments_under already:
autoload -U split-shell-arguments
function _split_shell_arguments_under()
{
local -a reply
integer REPLY2
split-shell-arguments
#have to duplicate some of modify-current-argument to get the word
#_under_ the cursor, not after.
setopt localoptions noksharrays multibyte
if (( REPLY > 1 )); then
if (( REPLY & 1 )); then
(( REPLY-- ))
fi
fi
REPLY=${(Q)reply[$REPLY]}
}
function helpme()
{
local REPLY
_split_shell_arguments_under
run-help $REPLY
}
zle -N helpme
bindkey '^Xh' helpme
--
Mikael Magnusson
^ 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).