0

I would like to execute a zle command without binding it to a key. The only solution I currently see is something like this.

cmd() { RBUFFER="some text to enter into the prompt" }
zle -N cmd
bindkey '^]'
sleep 0.05 && xdotool key Control+bracketright

If I would source this piece it would directly execute the widget, but this is rather ugly. Is there a way to execute the widget directly from inside the shell, or even from a script, without sourcing it?

EDIT: what I maybe generally would like to have is a way to manipulate zle stuff like RBUFFER, LBUFFER etc. from any zsh script.

  • I found this too, and no I think it doesn't. Here again a zle command has to executed, by typing through a special internal prompt in the shell. AFAIK it can't be programmed, nor can it be executed inside a shell script. I read some stuff about TRAPALRM, which is cool, but the minimum possible time (as it looks) is 1 second, so the function will be called each second, and for my purpose that wouldn't be snappy enough tbh. – Dimfred Apr 19 '22 at 21:51
  • okay maybe it is a duplicate, essentially he asked for the same thing. I read a bit more through the discussion, and no one had a good answer, so maybe it is just impossible to achieve that without a keybinding. – Dimfred Apr 19 '22 at 21:55
  • I have troubles to understand your approach. RBUFFER etc. is only meaningful when there is something written on the command line ("zle is active"), but how do you want to execute a script then? If you want to prefill the commandline, maybe print -z will help you. – mpy Apr 20 '22 at 17:34
  • print -z also only works, when executed in the same env, so if I do zsh -c print -z "bla" it won't work. The thing is I just want to have 100% control over zle stuff, from external.

    Currently I achieved this by reading a queue during trapalarm, and execute the read command. A command e.g. could be RBUFFER=bla; zle reset-prompt. So externally I now can push something into the buffer and it is interpreted in zle context. But TMOUT can only be set to 1 second, and thats not snappy enough for me as said.

    – Dimfred Apr 21 '22 at 10:10
  • Ok, my last idea is that you might get some inspiration from syntax highlighting scripts, there are some different ones out there; zsh-syntax-highlighting uses e.g. the add-zle-hook-widget functionality of zsh > 5.8. – mpy Apr 21 '22 at 18:14
  • Yeah I also looked at some hooks, but those are triggered on certain stuff which happens inside the shell, e.g. on key enter or something, which means it is triggered by events popped inside the shell. Since I want to have an external trigger, I don't think hooks will be of great help. Tho I probably have to check more, maybe I find something I could abuse for that. Thank you for your input so far :) – Dimfred Apr 22 '22 at 06:33

0 Answers0