Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Returning last parameter of a history command



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@xxxxxxx>                  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



Messages sorted by: Reverse Date, Date, Thread, Author