Skip to content

Commit 4cb1bc3

Browse files
author
John Mutuma (from Dev Box)
committed
fix(tmux): forward nav keys directly to mux pane on Windows (psmux)
On Windows with psmux, control keys like C-j passed through Neovim's terminal emulation get mangled (C-j/newline becomes CR/submit). Route nav key passthrough via tmux send-key when a mux parent is available, bypassing the terminal translation layer. Sanitize session names (spaces to hyphens) and sync mux_session so tmux send-keys targets the correct session on psmux.
1 parent b1c28c5 commit 4cb1bc3

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

lua/sidekick/cli/actions.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ local function nav(dir)
4747
return function(terminal)
4848
local at_edge = vim.fn.winnr() == vim.fn.winnr(dir)
4949
if at_edge or terminal:is_float() then
50+
-- When running under a mux backend (e.g., tmux via psmux on Windows),
51+
-- returning the key as an expr string passes through Neovim's terminal
52+
-- emulation, which can mangle control characters (e.g., C-j becomes CR).
53+
-- Send the key directly to the mux pane instead.
54+
if terminal.parent and terminal.parent.send_key then
55+
vim.schedule(function()
56+
terminal.parent:send_key(("C-%s"):format(dir))
57+
end)
58+
return
59+
end
5060
return ("<c-%s>"):format(dir)
5161
end
5262
vim.schedule(function()

lua/sidekick/cli/session/tmux.lua

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,20 @@ end
3030
---@return sidekick.cli.terminal.Cmd?
3131
function M:start()
3232
if not self.external then
33-
local cmd = { "tmux", "new", "-A", "-s", self.id }
33+
-- Sanitize session name: replace spaces with hyphens for psmux/Windows compatibility
34+
local session_name = self.id:gsub("%s+", "-")
35+
self.mux_session = session_name
36+
local cmd = { "tmux", "new", "-A", "-s", session_name }
3437
vim.list_extend(cmd, { "-c", self.cwd })
3538
self:add_cmd(cmd)
3639
if vim.fn.has("win32") == 1 then
3740
-- On Windows (psmux), ";" command chaining is not supported.
3841
-- PowerShell interprets ";" as a statement separator, causing
3942
-- "set-option" to be run as a standalone cmdlet (which fails).
4043
-- Instead, run set-option as separate commands after the session starts.
41-
local id = self.id
4244
vim.defer_fn(function()
43-
vim.fn.system({ "tmux", "set-option", "-t", id, "status", "off" })
44-
vim.fn.system({ "tmux", "set-option", "-t", id, "detach-on-destroy", "on" })
45+
vim.fn.system({ "tmux", "set-option", "-t", session_name, "status", "off" })
46+
vim.fn.system({ "tmux", "set-option", "-t", session_name, "detach-on-destroy", "on" })
4547
end, 1000)
4648
else
4749
vim.list_extend(cmd, { ";", "set-option", "status", "off" })
@@ -198,6 +200,14 @@ function M:submit()
198200
Util.exec({ "tmux", "send-keys", "-t", self.tmux_pane_id, "Enter" })
199201
end
200202

203+
---Send a raw key to a tmux pane
204+
---@param key string tmux key name (e.g., "C-j", "Enter", "Escape")
205+
function M:send_key(key)
206+
if self.mux_session then
207+
Util.exec({ "tmux", "send-keys", "-t", self.mux_session, key })
208+
end
209+
end
210+
201211
function M:dump()
202212
local pane_id = self:pane_id()
203213
if not pane_id then

0 commit comments

Comments
 (0)