-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsend.lua
More file actions
46 lines (42 loc) · 1.44 KB
/
Copy pathsend.lua
File metadata and controls
46 lines (42 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
local selectors = require("tmutils.selectors")
local F = require("tmutils.functions")
local M = {}
---Sends lines to a tmux pane.
---@param lines string[]
---@param pane string
local function send_lines(lines, pane)
local text = F.join_lines(lines)
local _ = vim.fn.jobstart(string.format('tmux send -t %s "%s"', pane, text), {
on_stdout = nil,
stdout_buffered = true,
})
end
---Sends a range of line into a tmux pane.
---@param opts {args: string, line1: integer, line2: integer} # User command options.
---@param conf Config | {} # Plugin configuration
M.tmux_send = function(opts, conf)
local lines = F.map(vim.api.nvim_buf_get_lines(0, opts.line1 - 1, opts.line2, false), F.str2cmd)
local selector_conf = conf.selector or { selector = selectors.vim_ui_selector }
local selector = selector_conf.selector or selectors.vim_ui_selector
if opts.args:len() ~= 0 then
local args = vim.split(opts.args, " ")
if #args ~= 1 then
error("Expected 1 arguments")
end
send_lines(lines, args[1])
elseif vim.g.tmutils_selected_pane ~= nil then
send_lines(lines, vim.g.tmutils_selected_pane)
else
local _ = vim.fn.jobstart("tmux list-panes -a", {
---@param data string[]
on_stdout = function(_, data, _)
local matches = F.parse_tmux_panes(data)
selector(F.map(matches, F.pane2str), "Select a pane:", function(selected_opt)
send_lines(lines, vim.split(selected_opt, " ")[1])
end)
end,
stdout_buffered = true,
})
end
end
return M