How can I use bindkey to run a script?

I think you do not need widget for that:

bindkey -s '\eb' '/path/to/script.sh\n' 

From zsh docs:

As well as ZLE commands, key sequences can be bound to other strings, by using ‘bindkey -s’.


You can define a widget that calls your script:

my-script_widget() my-script its args
zle -N my-script_widget
bindkey '\ej' my-script_widget

But why would you want to call your script directly from the zle?

If it displays anything, it will mess up the display. If you want its output displayed as other widget messages, you can do:

my-script_widget() zle -M "$(my-script its args)"

Or if you want the output inserted at the cursor:

my-script_widget() LBUFFER+=$(my-script its args)

Tags:

Zsh