Re: A ZLE widget for calculator
Erik Wybouw <[email protected]> Sun, 29 Mar 2026 19:13:59 +0200
| Newsgroups | gmane.comp.shells.zsh.user |
|---|---|
| Message-ID | <[email protected]> |
sure thing, much cleaner and simpler. Thanks!
if (( ! ${+aliases[=]} )); then
# only do this once, even if the file is sourced multiple times
function quote_expression() {
if [[ ${BUFFER} =~ ^=.* ]]; then
# used below in history hack
typeset -g calc_hist="${BUFFER}"
# add quotes
BUFFER="= ${(q-)${${BUFFER#=}# }}"
fi
}
# as per Bart Schaefer's comment
add-zle-hook-widget line-finish quote_expression
...
}
Next thing: force my luck, and make it also do stuff like
printf “the answer is %s\n” $(= 4 * 3)
Kind regards, erik.
—
Erik Wybouw
> On 28 Mar 2026, at 00:49, Bart Schaefer <[email protected]> wrote:
>
> On Fri, Mar 27, 2026 at 2:05 PM Erik Wybouw <[email protected]> wrote:
>>
>> Thank you for the inspiration!
>>
>> I just augmented it with a trick I use to chain accept-line handlers (my own, and zsh_autosuggest)
>
> You might consider doing this with
> add-zle-hook-widget line-finish quote_expression
> instead. That's actually designed for chaining a series of actions.
> It does execute after accept-line, but before handing the buffer over
> for execution, so you can do most things you would otherwise do in an
> accept-line override. The one thing it can't do is skip the
> accept-line entirely.