* commit to history
@ 2021-08-27 21:14 Pier Paolo Grassi
2021-08-27 21:59 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Pier Paolo Grassi @ 2021-08-27 21:14 UTC (permalink / raw)
To: Zsh-Users List
[-- Attachment #1: Type: text/plain, Size: 643 bytes --]
Hello, I have a zle widget that I use to send the current buffer to the
history without executing it, and then start a new prompt (to clear the
buffer and reset the current history position), it is implemented a such:
commit_to_history() {
print -s ${(q)${(z)BUFFER}}
zle send-break
}
the send-break widget returns a status code 1, and since I have a precmd
that displays the last status code, I was wondering if it is in some way
possibile to suppress that return status. I have tried with {zle
send-break} always {TRY_BLOCK_ERROR=0} but didn't help. It is a very minor
annoyance, but I am curious nonetheless
thanks
Pier Paolo Grassi
[-- Attachment #2: Type: text/html, Size: 952 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: commit to history
2021-08-27 21:14 commit to history Pier Paolo Grassi
@ 2021-08-27 21:59 ` Bart Schaefer
2021-08-28 19:34 ` Pier Paolo Grassi
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2021-08-27 21:59 UTC (permalink / raw)
To: Pier Paolo Grassi; +Cc: Zsh-Users List
On Fri, Aug 27, 2021 at 2:15 PM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>
> the send-break widget returns a status code 1, and since I have a precmd that displays the last status code, I was wondering if it is in some way possibile to suppress that return status.
The short answer is no, there is not. There was a long thread about
this on zsh-workers earlier this year, search "curious incident of the
feep".
As written your widget discards multi-line structures if invoked at
the PS2 prompt. If that's intentional you can replace with:
commit_to_history() {
print -rs -- ${(q)${(z)BUFFER}}
BUFFER=''
if [[ -n $PREBUFFER ]]
then zle accept-line
else zle send-break
fi
}
If you would prefer to capture multi-line structure at PS2,
commit_to_history() {
local fullbuffer="$PREBUFFER$BUFFER"
print -rs -- ${(q)${(z)fullbuffer}}
BUFFER=''
if [[ -n $PREBUFFER ]]
then zle accept-line
else zle send-break
fi
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: commit to history
2021-08-27 21:59 ` Bart Schaefer
@ 2021-08-28 19:34 ` Pier Paolo Grassi
0 siblings, 0 replies; 3+ messages in thread
From: Pier Paolo Grassi @ 2021-08-28 19:34 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh-Users List
[-- Attachment #1: Type: text/plain, Size: 1902 bytes --]
It seems that zle send-break commits to history the content of PREBUFFER
when used from PS2, does this makes sense?
I replicated it with:
echo abc\<enter>
> def<ctrl-G>
now the first item in the history is:
: 1630178520:0;E qwe\
this is wrong, due to the \ at the end of the row that will make the
subsequent row treated as part of a multi-line construct but it is not,
only the first line has been inserted in the history. in my case the
following line in .zsh_history is:
: 1630178638:0;tail -n 1 ~/.zsh_history
if I insert more lines before pressing ctrl-g just the last one is missing:
echo ab\<enter>
> bc\<enter>
> de<ctrl-G>
tail -n 3 zsh-history
: 1630178860:0;echo ab\\
bc\
: 1630178870:0;tail -n 3 ~/.zsh_history
this may be due to my very old zsh (5.1.1)
Pier Paolo Grassi
Il giorno ven 27 ago 2021 alle ore 23:59 Bart Schaefer <
schaefer@brasslantern.com> ha scritto:
> On Fri, Aug 27, 2021 at 2:15 PM Pier Paolo Grassi <pierpaolog@gmail.com>
> wrote:
> >
> > the send-break widget returns a status code 1, and since I have a precmd
> that displays the last status code, I was wondering if it is in some way
> possibile to suppress that return status.
>
> The short answer is no, there is not. There was a long thread about
> this on zsh-workers earlier this year, search "curious incident of the
> feep".
>
> As written your widget discards multi-line structures if invoked at
> the PS2 prompt. If that's intentional you can replace with:
>
> commit_to_history() {
> print -rs -- ${(q)${(z)BUFFER}}
> BUFFER=''
> if [[ -n $PREBUFFER ]]
> then zle accept-line
> else zle send-break
> fi
> }
>
> If you would prefer to capture multi-line structure at PS2,
>
> commit_to_history() {
> local fullbuffer="$PREBUFFER$BUFFER"
> print -rs -- ${(q)${(z)fullbuffer}}
> BUFFER=''
> if [[ -n $PREBUFFER ]]
> then zle accept-line
> else zle send-break
> fi
> }
>
[-- Attachment #2: Type: text/html, Size: 2935 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-08-28 19:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-27 21:14 commit to history Pier Paolo Grassi
2021-08-27 21:59 ` Bart Schaefer
2021-08-28 19:34 ` Pier Paolo Grassi
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).