vis-config
lua scripts to configure vis editor
git clone https://9o.is/git/vis-config.git
commit f63b540c3868f831a566adb8ae37aba4a28c94e1 parent ad24747f66b75a6815fb594b9fbffc36d095eea4 Author: Jul <jul@9o.is> Date: Thu, 26 Feb 2026 06:55:19 +0800 move tmux out of lib/window-manager Diffstat:
| A | lib/tmux.lua | | | 91 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | lib/window-manager/init.lua | | | 5 | ----- |
| D | lib/window-manager/tmux.lua | | | 71 | ----------------------------------------------------------------------- |
3 files changed, 91 insertions(+), 76 deletions(-)
diff --git a/lib/tmux.lua b/lib/tmux.lua @@ -0,0 +1,90 @@ +local M = { + enabled = true, + status = { + left = '', + right = '', + }, +} + +local function write(cmd) + if M.running() then + vis:info('tmux client is not running') + return false + end + M.fd:write(cmd .. '\n') + M.fd:flush() + return true +end + +M.init = function() + M.id = os.getenv('TMUX_PANE') + + if not M.id then + return + end + + M.fd = vis:communicate('tmux', + string.format("exec env -u TMUX tmux -C attach -t %s", M.id)) + + vis.events.subscribe(vis.events.PROCESS_RESPONSE, function(name, event, code, msg) + if name ~= 'tmux' then + return + end + + if event == 'EXIT' then + vis:info('tmux client exited: ' .. code) + elseif event == 'SIGNAL' then + vis:info('tmux client received signal: ' .. code) + end + end) +end + +M.running = function() + return io.type(M.fd) ~= 'file' +end + +M.navigate = function(path, cmd) + cmd = cmd and "+'"..cmd.."'" or '' + return write(string.format('new-window -b vis %s %s', cmd, path)) +end + +M.tabnew = function(argv) + local command = table.concat(argv, ' ') + return write('new-window -b vis ' .. command) +end + +M.terminal = function(argv) + local command = table.concat(argv, ' '):gsub('"', '\\"') + return write(string.format('new-window -b "%s"', command)) +end + +M.set_title = function(title) + return write(string.format("select-pane -t %s -T '%s'", M.id, title)) +end + +M.set_status = function(left, right) + if left and left ~= M.status.left then + M.status.left = left + return write(string.format("set -pt %s @pane_left_status '%s'", M.id, right)) + end + + if right and right ~= M.status.right then + M.status.right = right + return write(string.format("set -pt %s @pane_right_status '%s'", M.id, right)) + end +end + +vis.events.subscribe(vis.events.INIT, function() + if M.enabled then + M.init() + end +end) + +vis.events.subscribe(vis.events.WIN_OPEN, function() + if M.running() then + vis:command_register('tabnew', M.tabnew, 'Run vis command in a new tab page') + vis:command_register('terminal', M.terminal, 'Run shell command in a new tab page') + end +end) + +return M +\ No newline at end of file diff --git a/lib/window-manager/init.lua b/lib/window-manager/init.lua @@ -1,4 +1,3 @@ -local tmux = require('lib/window-manager/tmux') local x11 = require('lib/window-manager/x11') local wm = 'none' @@ -24,10 +23,6 @@ local M = { } M.init = function() - if wm == 'tmux' and os.getenv('TMUX') then - M.strategy = tmux - M.strategy.init() - end if wm == 'x11' and os.getenv('WINDOWID') then M.strategy = x11 M.strategy.init() diff --git a/lib/window-manager/tmux.lua b/lib/window-manager/tmux.lua @@ -1,70 +0,0 @@ -local fd -local pane_id - -local function write(cmd) - if io.type(fd) ~= 'file' then - vis:info('tmux client is not running') - return false - end - fd:write(cmd .. '\n') - fd:flush() - return true -end - -local tmux = {} - -tmux.init = function() - pane_id = os.getenv('TMUX_PANE') - - if not pane_id then - return - end - - fd = vis:communicate('tmux', - string.format("exec env -u TMUX tmux -C attach -t %s", pane_id)) - - vis.events.subscribe(vis.events.PROCESS_RESPONSE, function(name, event, code, msg) - if name ~= 'tmux' then - return - end - - if event == 'EXIT' then - vis:info('tmux client exited: ' .. code) - elseif event == 'SIGNAL' then - vis:info('tmux client received signal: ' .. code) - end - end) -end - -tmux.enabled = function() - return io.type(fd) == 'file' -end - -tmux.hasstatus = function() - return true -end - -tmux.navigate = function(path, cmd) - cmd = cmd and "+'"..cmd.."'" or '' - return write(string.format('new-window -b vis %s %s', cmd, path)) -end - -tmux.tabnew = function(argv) - local command = table.concat(argv, ' ') - return write('new-window -b vis ' .. command) -end - -tmux.terminal = function(argv) - local command = table.concat(argv, ' '):gsub('"', '\\"') - return write(string.format('new-window -b "%s"', command)) -end - -tmux.set_title = function(title) - return write(string.format("select-pane -t %s -T '%s'", pane_id, title)) -end - -tmux.set_status = function(status) - return write(string.format("set -pt %s @pane_status '%s'", pane_id, status)) -end - -return tmux -\ No newline at end of file