Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions lua/sidekick/cli/session/tmux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@ function M:spawn(cmd)
if pane then
self.id = pane.skid
self.tmux_pane_id = pane.id
self.mux_session = pane.session_name

local display_name = pane.session_name
local lines = Util.exec({
"tmux", "display-message", "-p", "-t", pane.id,
"#{session_name}:#{window_index}.#{pane_index}"
}, { notify = false })
if lines and lines[1] then
display_name = lines[1]:gsub("%s+$", "")
end

self.mux_session = display_name
self.tmux_pid = pane.pid
self.started = true
end
Expand Down Expand Up @@ -136,13 +146,23 @@ function M.sessions()
if tool:is_proc(proc) then
local pids = Procs.pids(pane.pid)
vim.list_extend(pids, clients[pane.session_id] or {})

local display_name = pane.session_name
local lines = Util.exec({
"tmux", "display-message", "-p", "-t", pane.id,
"#{session_name}:#{window_index}.#{pane_index}"
}, { notify = false })
if lines and lines[1] then
display_name = lines[1]:gsub("%s+$", "")
end

ret[#ret + 1] = {
id = pane.skid,
cwd = proc.cwd or pane.cwd,
tool = tool,
tmux_pane_id = pane.id,
tmux_pid = pane.pid,
mux_session = pane.session_name,
mux_session = display_name,
pids = pids,
}
return true
Expand All @@ -159,7 +179,8 @@ function M:pane_id()
return self.tmux_pane_id
end
if not self.external then
self:spawn({ "tmux", "list-panes", "-s", "-F", PANE_FORMAT, "-t", self.mux_session })
local session_name = self.mux_session and self.mux_session:match("^([^:]+)") or self.mux_session
self:spawn({ "tmux", "list-panes", "-s", "-F", PANE_FORMAT, "-t", session_name })
end
return self.tmux_pane_id
end
Expand Down
6 changes: 4 additions & 2 deletions lua/sidekick/cli/ui/select.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ function M.format(state, picker)

local backends = {} ---@type string[]
backends[#backends + 1] = state.session.mux_backend or state.session.backend
if state.external then
backends[#backends + 1] = state.session.mux_session
local mux_session = state.session.mux_session or (state.session.parent and state.session.parent.mux_session)
-- Check if it's an opencode session since we populate mux_session with the tmux session+pane id
if state.external or (state.tool and state.tool.name == "opencode") or mux_session then
backends[#backends + 1] = mux_session
end
local backend = ("[%s]"):format(table.concat(backends, ":"))

Expand Down
7 changes: 7 additions & 0 deletions lua/sidekick/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ local function update_cli_status()
local Session = require("sidekick.cli.session")
cli_sessions = {}
for id, session in pairs(Session.attached()) do
local mux_session = session.mux_session
if session.parent and session.parent.mux_session then
mux_session = session.parent.mux_session
end

cli_sessions[id] = {
id = session.id,
tool = session.tool.name,
cwd = session.cwd,
mux_backend = session.mux_backend or session.backend,
mux_session = mux_session,
}
end
end
Expand Down
27 changes: 26 additions & 1 deletion sk/cli/opencode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ M.__index = M
M.priority = 20
M.external = true

local function get_mux_session(pid)
local Util = require("sidekick.util")
local env = require("sidekick.cli.procs").env(pid)
if not env then
return nil
end

local tmux_pane = env["TMUX_PANE"]
if not tmux_pane then
return nil
end

local lines = Util.exec({
"tmux", "display-message", "-p", "-t", tmux_pane,
"#{session_name}:#{window_index}.#{pane_index}"
}, { notify = false })

if lines and lines[1] then
-- Strip any trailing newlines or whitespace
return lines[1]:gsub("%s+$", "")
end

return nil
end

function M.sessions()
local Procs = require("sidekick.cli.procs")
local Util = require("sidekick.util")
Expand Down Expand Up @@ -44,7 +69,7 @@ function M.sessions()
cwd = Procs.cwd(pid) or "",
port = port,
pids = Procs.pids(pid),
mux_session = tostring(pid),
mux_session = get_mux_session(pid) or tostring(pid),
base_url = ("http://localhost:%d"):format(port),
}
end
Expand Down