I'm writing a simple ZLE widget to quickly create subshells with <C-j>
. Here's what I have:
function zle_subshell {
zle -U '$()'
zle .backward-char
}
# register as widget
zle -N zle_subshell
# create kbd
bindkey '^j' zle_subshell
However, it appears that zle .backward-char
isn't working. What makes matters more confusing is that if I modify the script to be:
function zle_subshell {
zle -U '$('
zle -U ')'
zle .backward-char
}
I get output like )$(
...
It appears that zle_subshell
function is being evaluated in reverse. Are there some obvious gotchas with ZLE widgets that I'm unaware of?
The
zle -U
usage is the pecial case. It seems that the behavior is intended:So, zsh will behave as if
)
and$(
were typed after thezle_subshell
finishes.We could modify the
(R)BUFFER
to change the editor buffer directly like this: