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

Re: print -s and History Expansion



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