-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtmux-repl.lua
56 lines (52 loc) · 2 KB
/
tmux-repl.lua
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
47
48
49
50
51
52
53
54
55
-- Set the REPL target pane for the current window to the given pane ID.
-- If no pane ID is supplied, the command will look for the marked pane
-- and try to use it. It prints an error message if there is no marked pane.
vis:command_register("repl-set", function(argv, _, win)
local pane = argv[1]
if not pane then
local f = io.popen("tmux lsp -a -F \"#D #{pane_marked}\" \\;" ..
" select-pane -M " ..
"| awk '$2 == 1 { print $1; }'")
for line in f:lines() do
pane = line
end
f:close()
end
if pane then
win.repl_target_pane = pane
else
vis:message("repl-set: No pane ID given and no marked pane!")
end
end)
-- Open a new pane and set it to the REPL target pane of the current window.
-- Optionally, a command can be provided, which is then executed
-- in the opened pane. E.g.:
-- :repl-new python3
vis:command_register("repl-new", function(argv, _, win)
local pane;
local cmd = (argv[1] or "")
local f = io.popen("tmux splitw -d -l 10 -P -F '#D' " .. cmd)
for line in f:lines() do
pane = line
end
f:close()
win.repl_target_pane = pane
end)
-- Sends the selected text to the REPL target pane. (use in visual mode)
vis:command_register("repl-send", function(argv, _, win)
if win.repl_target_pane then
vis:command('> sed \'s/;$/\\\\\\;/g; s/\\(.*\\)/\\1\\\\nEnter/\' ' ..
' | tr "\\\\n" "\\0" ' ..
' | xargs -0 tmux send-keys -t ' .. win.repl_target_pane)
end
end)
-- Sends the given line of text to the REPL target pane.
-- Can be used to call a command in the other pane, for example to recompile
-- your project, you can open a shell in the target pane and use:
-- :repl-send make
vis:command_register("repl-sendln", function(argv, _, win)
if win.repl_target_pane then
vis:command('! tmux send-keys -t '.. win.repl_target_pane ..
' ' .. argv[1] .. ' Enter')
end
end)