Zsh creates a command line in a script, but does not execute it

I am wondering if it is possible to write a zsh script that will write the command at the invitation, but DO NOT execute it, that is, leave it there for editing and then execute it when I am ready. I can do something similar using keybindings, leaving the final "\ Cm". eg:

bindkey -s "\e[1;3C" "howdy!"

... I press Alt + RightArrow and the text "howdy!" printed in the invitation and just stays there.

I can also do something like what I want by writing my command to the history file and then remembering it with the up arrow. I tried "echo -n sometext" but it does not work.

Can I write a script that will exit the command line (say) "howdy!"? Actually, I want the script to create a complex command based on several things, but I want the script to leave it in the CLI for final editing, so automatic execution should be prevented.

Thanks in advance.

+3
source share
2 answers

It turns out the answer is simple:

print -z $string-to-print
+4
source

If you mean the zsh function, not the external script, you can write a zle widget (short for the zsh line editor) and bind it to some key.

# define to function to use
hello () {
 BUFFER=hello
 zle end-of-line
}
# create a zle widget, which will invoke the function.
zle -N hello
# bindkey Alt-a to that widget
bindkey "\ea" hello

You can learn more from the Z-Shell User Guide, chapter 4 .

+1
source

All Articles