From cab9ae5285a140fab9f4341a8e20eb24b08adca5 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 29 May 2026 10:01:10 +0300 Subject: feat: prioritize agent-labeled tmux sessions when attaching --- fish/conf.d/tmux.fish | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/fish/conf.d/tmux.fish b/fish/conf.d/tmux.fish index 4d77b07..c1831b6 100644 --- a/fish/conf.d/tmux.fish +++ b/fish/conf.d/tmux.fish @@ -71,13 +71,23 @@ function tmux::attach return 1 end tmux attach-session || tmux::new - else - if test -n "$TMUX" - tmux switch-client -t "=$session" 2>/dev/null; or tmux::new $session $dir - else - tmux attach-session -t "=$session" 2>/dev/null; or tmux::new $session $dir + return + end + + # Prefer attaching to an agent-labeled session if one exists. + # Never create A-prefixed sessions via shortcuts; only prioritize them. + for prefixed in "A-$session" "A$session" + if tmux has-session -t "=$prefixed" 2>/dev/null + set session $prefixed + break end end + + if test -n "$TMUX" + tmux switch-client -t "=$session" 2>/dev/null; or tmux::new $session $dir + else + tmux attach-session -t "=$session" 2>/dev/null; or tmux::new $session $dir + end end function tmux::remote -- cgit v1.2.3