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

Re: accept-line question



(don't write your reply up here)
On Fri, Apr 3, 2015 at 12:40 AM, Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Thu, Apr 2, 2015 at 2:50 PM, Dave Yost <Dave@xxxxxxxx> wrote:
>> That works.
>>
>> I do want the executed command to be inserted into history.
>>
>> I searched the manual in vain for a way to do that. Any chance you could
>> illuminate further?
>
> Try this:
>
> --- 8< ---
> execute-now() {
>   zle -I
>   print -S "$BUFFER"
>   eval "$BUFFER"
>   BUFFER=
>   zle -R
> }
> --- 8< ---
>
> Remaining glitches will be that $? / $pipestatus won't be correct when
> redrawing the prompt or executing a subsequent command.  I can't
> immediately think of a workaround.

This mostly works, the only caveat is that the commands are executed
in the reverse order:
xxx() {
 zle push-input
 BUFFER="$1"
 zle -U $'\n'
}
x1() { xxx 'echo 1' }
x2() { xxx 'echo 2'; xxx 'echo 3' }
zle -N x{1,2}

Executing x2 will print 3 and then 2 because of how stacks work.

-- 
Mikael Magnusson



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