Something went wrong. Try again.
Making Kakoune Rex-aware
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849---- send.lua: paste text into a Rex terminal block.---- Usage: REX_KAK_TEXT='select 42;' rex do -s SESSION send.lua block=BLOCK_ID---- The text comes from the environment rather than a key=value argument,-- because rex do types those by how they're written (1.50 becomes 1.5).---- If the text ends with a newline, Enter is sent separately after the paste,-- so REPLs with bracketed paste on still run it. Rex API calls return nil-- plus an error rather than raising, so each one is checked.--
local block_id = rex.args.blocklocal text = os.getenv("REX_KAK_TEXT") or ""
if not block_id or block_id == "" then error("block is required")endif text == "" then error("nothing to send")end
local body = text:gsub("\n+$", "")local submit = body ~= text
if body ~= "" then local _, err = rex.call("block.event", { session_id = rex.session_id, block_id = block_id, event = { type = "paste", payload = { text = body } }, }) if err then error(err) endend
if submit then local _, err = rex.block.call("com.superlogical.terminal", "write", { block_id = block_id, data = "\r", }) if err then error(err) endend
return #text