feat(tmux): new tmux session selector using rofi

This commit is contained in:
2026-06-06 17:09:52 -04:00
parent 70d2eb2e65
commit f5f795d660
3 changed files with 38 additions and 29 deletions
+30 -10
View File
@@ -227,6 +227,36 @@ function focus_or_launch(opts)
hl.exec_cmd(cmd)
end
function fetch_or_launch(opts)
local match = opts.match
local cmd = opts.cmd
local field = opts.field or "class" -- class, title, initialClass, initialTitle
local use_workspace = opts.use_workspace ~= false
local clients = hl.get_windows()
local active_workspace = hl.get_active_workspace()
for _, client in ipairs(clients) do
local value = client[field]
if value and string.find(string.lower(value), string.lower(match), 1, true) then
if use_workspace and client.workspace and client.workspace.id then
hl.dispatch(hl.dsp.window.move({
workspace = active_workspace.id,
on_current_monitor = true,
}))
end
hl.dispatch(hl.dsp.focus({
window = "address:" .. client.address
}))
return
end
end
hl.exec_cmd(cmd)
end
function toggle_master()
local ws = hl.get_active_workspace()
if not ws then
@@ -259,16 +289,6 @@ hl.bind(LEADER .. "return", function()
})
end, { description = "Open terminal" })
--hl.bind(LEADER .. "SHIFT + return", hl.dsp.exec_raw(terminal .. "tmux attach-session -t $(tmux list-windows -a -F '#S:#I' | rofi -dmenu -P Session)"))
hl.bind(LEADER .. "SHIFT + return", function()
local session = io.popen("tmux list-sessions -F '#S:#I' | rofi -dmenu -P Session"):read("*a")
hl.notification.create({ text = "Attaching to tmux session: " .. session, icon = "hint", duration = 2000 })
focus_or_launch({
match = "session",
field = "title",
cmd = terminal .. " -e tmux attach-session -t " .. session
})
end, { description = "Attach to tmux session" })
hl.bind(LEADER .. "B", hl.dsp.exec_raw(browser), { description = "Open browser" })
hl.bind(LEADER .. "T", hl.dsp.exec_raw(terminal .. " -e btop"), { description = "Open system monitor" })