feat(tmux): new tmux session selector using rofi
This commit is contained in:
+30
-10
@@ -227,6 +227,36 @@ function focus_or_launch(opts)
|
|||||||
hl.exec_cmd(cmd)
|
hl.exec_cmd(cmd)
|
||||||
end
|
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()
|
function toggle_master()
|
||||||
local ws = hl.get_active_workspace()
|
local ws = hl.get_active_workspace()
|
||||||
if not ws then
|
if not ws then
|
||||||
@@ -259,16 +289,6 @@ hl.bind(LEADER .. "return", function()
|
|||||||
})
|
})
|
||||||
end, { description = "Open terminal" })
|
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 .. "B", hl.dsp.exec_raw(browser), { description = "Open browser" })
|
||||||
hl.bind(LEADER .. "T", hl.dsp.exec_raw(terminal .. " -e btop"), { description = "Open system monitor" })
|
hl.bind(LEADER .. "T", hl.dsp.exec_raw(terminal .. " -e btop"), { description = "Open system monitor" })
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
# auto rename windows
|
# auto rename windows
|
||||||
set -g automatic-rename on
|
set -g automatic-rename on
|
||||||
|
set -g automatic-rename-format '#{pane_current_command} #{b:pane_current_path}'
|
||||||
set -g allow-rename on
|
set -g allow-rename on
|
||||||
|
|
||||||
# start with window 1 (instead of 0)
|
# start with window 1 (instead of 0)
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
sessions="$(tmux list-sessions -F '#S' 2>/dev/null || true)"
|
#sessions="$(tmux list-sessions -F '#S' 2>/dev/null || true)"
|
||||||
|
sessions="$(tmux list-windows -a -F '#S #W::#S:#I' 2>/dev/null || true)"
|
||||||
|
|
||||||
[ -n "${sessions}" ] || exit 0
|
[ -n "${sessions}" ] || exit 0
|
||||||
|
|
||||||
walker_pick_session() {
|
walker_pick_session() {
|
||||||
@@ -12,11 +14,11 @@ walker_pick_session() {
|
|||||||
|
|
||||||
rofi_pick_session() {
|
rofi_pick_session() {
|
||||||
if command -v rofi >/dev/null 2>&1; then
|
if command -v rofi >/dev/null 2>&1; then
|
||||||
rofi -dmenu -p 'tmux sessions:'
|
rofi -i -dmenu -display-columns 1 -display-column-separator '::' -p 'tmux sessions:'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
chosen="$(printf '%s\n' "$sessions" | rofi_pick_session)"
|
chosen="$(printf '%s\n' "$sessions" | rofi_pick_session | awk -F'::' 'NR==1{print $NF}')"
|
||||||
|
|
||||||
[ -n "$chosen" ] || exit 0
|
[ -n "$chosen" ] || exit 0
|
||||||
|
|
||||||
@@ -24,19 +26,5 @@ if [ "${TMUX-}" ]; then
|
|||||||
exec tmux switch-client -t "${chosen}"
|
exec tmux switch-client -t "${chosen}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
client_tty="$(
|
session_name="${chosen%%:*}"
|
||||||
tmux list-clients -F '#{client_tty} #{client_termname}' 2>/dev/null \
|
tmux select-window -t $chosen && hyprctl dispatch "focus_or_launch({match = \"$session_name\", field = \"title\", cmd = \"foot -e tmux attach-session -t $chosen\"})"
|
||||||
| awk '$2 ~ /xterm/ { print $1; exit }' || true
|
|
||||||
)"
|
|
||||||
|
|
||||||
if [ -n "${client_tty}" ]; then
|
|
||||||
# switch that client to the chosen session
|
|
||||||
address=$(hyprctl clients -j | jq -r "to_entries | .[] | select(.value.class == \"foot\") | \"\(.value.address)\"")
|
|
||||||
workspace=$(hyprctl clients -j | jq -r ".[] | select(.address == \"$address\") | \"(.workspace.id)\"")
|
|
||||||
hyprctl dispatch "hl.dsp.focus({workspace = $workspace , on_current_monitor = true})"
|
|
||||||
hyprctl dispatch "hl.dsp.focus({ window = \"address:$address\" })"
|
|
||||||
tmux switch-client -c "${client_tty}" -t "${chosen}"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user