Single command to pipe %sh{} into buffer?

sample .kak file

Opening Command Output in a New Buffer - DEV Community

Pipe to register? - #3 by FlyingWombat

edit -scratch messages
exec ‘%d’
exec ‘|echo from exec;date’
set-register | %sh{
echo “from reg echo”;
date }
exec ‘"|pge’

line 5 using the | register is a very direct way of getting output from the shell into a buffer.
However it appears to fail with newlines i.e.
fails even when entered with the exec command.
I can get around this by writing a shell script and using it at the pipe prompt.
I would rather express the shell script in %sh{ } as at line 6 to avoid writing
a separate shell script.
Line 6 works but the best I can find so far requires the additional exec ‘"|p’
i.e. first copy the %sh output to the pipe register (or perhaps any register) then copy the register into the buffer.
Given there is a command to write %sh{} output to a register, is there a way to write %sh{} output into the current buffer (selection) in one step?


You might be able to do an execute-keys command starting with i to go into insert mode, followed by your %sh{} output. Something like this, for example:

execute-keys "i%sh{echo hello}"

Thanks, that works! including when splitting the commands inside %sh{} over multiple lines. `
execute-keys “i”%sh{echo hello} also works even when splitting the unquoted %sh{} over multiple lines as long as the %sh{ is on the first line. The unquoted %sh{} allows normal use of “” inside the %sh{} over multiple lines.
I’m glad it’s this simple. Going through the pipe register seemed overly complicated.