Changing the reorded history compared with what's actually executed
seems a reasonable thing to have, given all the other things you can do
with history.
I'm a little confused by this one:
On Mon, Feb 2, 2026 at 11:22 PM Vincent Bernat <bernat@xxxxxxxx> wrote:
_vbe_calc_accept_line() {
if [[ $BUFFER =~ "= *" ]]; then
local expr=${BUFFER#= }
zle -I
command numbat -e "$expr"
print
print -s $BUFFER
BUFFER=""
else
zle .accept-line
fi
}
The original problem statement as I understand it, is: When the buffer
starts with "= ", form a single quoted word to pass as an argument to
"numbat -e", but preserve the original buffer in the shell history.
The first implementation, which modifies $BUFFER and then calls
.accept-line, un-quotes and re-quotes the tail of the buffer. You
said:
a bit clunky to detect when something was quoted and undo it
The implementation above never handles the un-quote part. If that was
required in the first implementation, why is that no longer necessary
there? Won't unwanted extra quotes that appear in the original
$BUFFER be passed through to numbat via "$expr"?
I think the attached does what you want. It's based on the
modify-$BUFFER + .accept-line variation because among other things
that has the advantage of working at the PS2 prompt. It
unconditionally removes and re-adds quotes. The original $BUFFER is
saved in a global variable which is then added to the history by the
preexec hook, after suppressing the automatic history with
zshaddhistory hook. This could probably use a function instead of an
alias for "=", but I didn't change that.