* Returning last parameter of a history command
@ 2006-09-22 13:59 zzapper
2006-09-22 14:57 ` Peter Stephenson
2006-09-22 16:48 ` Roman Neuhauser
0 siblings, 2 replies; 4+ messages in thread
From: zzapper @ 2006-09-22 13:59 UTC (permalink / raw)
To: zsh-users
Hi
how should this done in zsh-speak
history -n -1|sed 's/^.* //
Where the sed returns the last parameter
--
http://successtheory.com/tips/ Vim, Zsh, MySQL Tips
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Returning last parameter of a history command
2006-09-22 13:59 Returning last parameter of a history command zzapper
@ 2006-09-22 14:57 ` Peter Stephenson
2006-09-23 10:23 ` zzapper
2006-09-22 16:48 ` Roman Neuhauser
1 sibling, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2006-09-22 14:57 UTC (permalink / raw)
To: zsh-users
zzapper wrote:
> Hi
>
> how should this done in zsh-speak
>
> history -n -1|sed 's/^.* //
>
> Where the sed returns the last parameter
zmodload -i zsh/parameter
print ${${(z)history[$((HISTCMD-1))]}[-1]}
Adjust the line number as necessary: it's $((HISTCMD-1)) when you're
getting the previous line at the prompt but it depends where you are
relative to the line being updated. Experiment.
Note that $history is an associative array; you need to get the line
number in the key exactly right.
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Returning last parameter of a history command
2006-09-22 13:59 Returning last parameter of a history command zzapper
2006-09-22 14:57 ` Peter Stephenson
@ 2006-09-22 16:48 ` Roman Neuhauser
1 sibling, 0 replies; 4+ messages in thread
From: Roman Neuhauser @ 2006-09-22 16:48 UTC (permalink / raw)
To: zzapper; +Cc: zsh-users
# david@tvis.co.uk / 2006-09-22 13:59:00 +0000:
> how should this done in zsh-speak
>
> history -n -1|sed 's/^.* //
!$ or alt-dot if I understand your question correctly.
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Returning last parameter of a history command
2006-09-22 14:57 ` Peter Stephenson
@ 2006-09-23 10:23 ` zzapper
0 siblings, 0 replies; 4+ messages in thread
From: zzapper @ 2006-09-23 10:23 UTC (permalink / raw)
To: zsh-users; +Cc: zsh-workers
Peter Stephenson <pws@csr.com> wrote in news:200609221457.k8MEvAhC028569
@news01.csr.com:
> zzapper wrote:
>> Hi
>>
>> how should this done in zsh-speak
>>
>> history -n -1|sed 's/^.* //
>>
>> Where the sed returns the last parameter
>
> zmodload -i zsh/parameter
> print ${${(z)history[$((HISTCMD-1))]}[-1]}
>
Thanx PWS
I have adapted this to
print ${${(z)$(history -n -1)}[-1]}
so that I can use on a generic command
I was not able to tell if any of the 3 versions was faster
--
zzapper
A Mini-Internet Business for less than $5 that you can set up in less
than 5
minutes!!
http://www.twodollars.biz/?a=532036
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-09-23 10:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-22 13:59 Returning last parameter of a history command zzapper
2006-09-22 14:57 ` Peter Stephenson
2006-09-23 10:23 ` zzapper
2006-09-22 16:48 ` Roman Neuhauser
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).