Skip to content

Commit

Permalink
feat: Add send-text command as a function (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
meisocafe authored Sep 26, 2024
1 parent f73bba2 commit 032c33b
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lua/wezterm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ end
---Exec an arbitrary command in wezterm (does not return result)
---@param args string[]
---@param handler fun(res: vim.SystemObj)
function wezterm.exec(args, handler)
---@param stdin string|string[]|boolean If `true`, then a pipe to stdin is opened and can be written to via the `write()` method to SystemObj. If string or string[] then will be written to stdin
function wezterm.exec(args, handler, stdin)
if not wezterm.setup({}) then
return
end
vim.system({ wezterm_executable, unpack(args) }, {
stdin = stdin,
text = true,
}, vim.schedule_wrap(handler))
end
Expand Down Expand Up @@ -479,6 +481,29 @@ function wezterm.switch_pane.direction(dir, pane)
wezterm.exec(args, exit_handler("activate pane by direction " .. dir))
end

---Send text to a pane
---@param text string Text to send
---@param pane integer | nil Specify thecurrent pane
---@param no_paste boolean|nil (default false)
function wezterm.send_text(text, pane, no_paste)
if not text then
err("text is required for send-text")
end

local args = { "cli", "send-text" }

if pane then
table.insert(args, "--pane-id")
table.insert(args, pane)
end

if no_paste then
table.insert(args, "--no-paste")
end

wezterm.exec(args, exit_handler("send text to pane"), text)
end

local function trim(str)
return str:gsub("^%s+", ""):gsub("%s+$", "")
end
Expand Down

0 comments on commit 032c33b

Please sign in to comment.