Skip to content

Commit

Permalink
DIY instead of vimux (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
NonlinearFruit committed Jan 26, 2024
1 parent 19eca75 commit cc83ae9
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 22 deletions.
21 changes: 21 additions & 0 deletions nvim/lua/plugins/runner.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
local function configure()
local runner = require("runner")
vim.keymap.set("n", "<leader>vd", runner.close, { desc = "[v]imux [d]elete" })
vim.keymap.set("n", "<leader>vp", runner.prompt, { desc = "[v]imux [p]rompt" })
vim.keymap.set("n", "<leader>vr", function() runner.run("!!") end, { desc = "[v]imux [r]erun the last command" })
vim.keymap.set(
"n",
"<leader>vz",
runner.zoom,
{ desc = "[v]imux [z]oom (tmux <leader>-z to toggle https://superuser.com/a/576505/468052)" }
)
end

return {
"local/runner",
cond = function()
return vim.fn.executable("tmux") == 1
end,
config = configure,
dev = true,
}
22 changes: 0 additions & 22 deletions nvim/lua/plugins/vimux.lua

This file was deleted.

44 changes: 44 additions & 0 deletions nvim/lua/runner.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
local M = {}

M.close = function()
local runner = M.getId()
if runner == '' then
return
end
os.execute("tmux kill-pane -t "..runner)
end

M.prompt = function()
local cmd = vim.fn.input("$ ")
M.run(cmd)
end

M.run = function(cmd)
local runner = M.getId()
if runner == '' then
os.execute("tmux split-window -p 40 -h")
os.execute("tmux last-pane")
runner = M.getId()
if runner == '' then
return
end
end
os.execute("tmux send-keys -t "..runner.." '"..cmd.."' ENTER")
end

M.zoom = function ()
local runner = M.getId()
os.execute("tmux resize-pane -Z -t "..runner)
end

M.getId = function()
local panes = vim.fn.systemlist("tmux list-panes -F '#{pane_active}:#{pane_id}'")
for _, pane in pairs(panes) do
if string.sub(pane,1,1) ~= "1" then
return string.sub(pane,3)
end
end
return ''
end

return M

0 comments on commit cc83ae9

Please sign in to comment.