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

Re: A ZLE widget for calculator



> On 03/02/2026 07:16 GMT Vincent Bernat <bernat@xxxxxxxx> wrote:
> # Simple calculator
> _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
> }
> zle -N accept-line _vbe_calc_accept_line
> 
> It almost work, but the buffer is not available in the immediate history 
> (because no accept-line was called). If I press the up arrow, I get the 
> previous one instead.

Does adding "print -s <line>" to the function work?

(I was thinking about getting the shell to ignore the line executed as
well --- there are features for this --- but it's not quite smooth as
the line does hang around until after you execute something else, so
doesn't look like that would be what you want.  But maybe you now have
enough anyway...)

cheers
pws




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