Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: print -s and History Expansion
- X-seq: zsh-users 10221
- From: Chris Johnson <cjohnson@xxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: print -s and History Expansion
- Date: Fri, 5 May 2006 14:05:17 -0400
- In-reply-to: <EXCHANGE03IEAOeIiGX00000e9c@xxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20060502191022.GA30399@xxxxxxxxxxxxxxxx> <200605022147.k42LlWC9003204@xxxxxxxxxxxxxxxxx> <20060504190631.GA29447@xxxxxxxxxxxxxxxx> <EXCHANGE03IEAOeIiGX00000e9c@xxxxxxxxxxxxxxxxxx>
Peter Stephenson sent me the following 1.4K:
> > 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
> > }
>
> 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.
I was able to get
commit-to-history() {
print -s ${(z)BUFFER}
zle send-break
}
zle -N commit-to-history
to work just fine. History expansion pulls in the split words of a just
committed-to-history line just fine, and the command line stays
displayed for reference. It's just like hitting ^C but adds the line to
history, which is exactly what I was looking for.
As far as your accept-line comment above, is the send-break widget not
supposed to behave the way it is? The line is immediately available for
history expansion (histverify is set):
[cjohnson@namib] ~: echo one two three
[cjohnson@namib] ~: echo !!:$
[cjohnson@namib] ~: echo three
three
--
Chris Johnson
cjohnson@xxxxxxxxxx
http://www.cs.utk.edu/~cjohnson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author