Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: print -s and History Expansion
- X-seq: zsh-users 10217
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: print -s and History Expansion
- Date: Fri, 05 May 2006 09:55:42 +0100
- In-reply-to: <20060504190631.GA29447@xxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20060502191022.GA30399@xxxxxxxxxxxxxxxx> <200605022147.k42LlWC9003204@xxxxxxxxxxxxxxxxx> <20060504190631.GA29447@xxxxxxxxxxxxxxxx>
Chris Johnson wrote:
> commit-to-history() {
> # zsplit current command, expand result to all its quoted fields
> # ("f1" "f2" "f3"), prepend it with a command to make it written
> # to history, and then execute it.
> BUFFER=" print -s ${${(z)BUFFER}[@]}"
> zle accept-line
> }
> zle -N commit-to-history
> bindkey "^X^H" commit-to-history
>
> I tried using ${(qq){$(z)BUFFER}} but that didn't work.
To avoid the extra command line execution I would use:
commit-to-history() {
print -s ${(z)BUFFER}
BUFFER=
zle accept-line
}
then there are no quoting problems. You still need the accept-line if
you plan on using what you've just added to the history immediately,
since otherwise the history isn't reread. However, it's now on an empty
buffer.
> Perhaps I could have stuck with the simpler bind, but it seems that
> somehow I need to get the command into a parameter before I can split
> it. Is there any way to expand literals?
There's no way to avoid using a parameter without doing worse things. Zle
widgets are anyway more readable and predictable than bindkey -s tricks.
--
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