I have a shell alias:
ssh -A -t hostname tmux new -A
this mostly does what I want. If there's an existing session on the remote host, it attaches to it. If there's no session, it creates a new one. This is exactly what I want most of the time, so I can get back to sessions orphaned by network failures.
The problem comes up when I occasionally want to open two session to the same host from different windows. When I run that command in the second window, it sees the existing session and attaches to it. I now have two windows attached to the same session. What I really want is:
If there's a *detached* session, attach to it
Else, create a new session.
Is this possible? If it matters, my desktop is MacOS and all my target hosts are Debian Linux. And I run with
set-option -g prefix None
in my .tmux.conf file.