The tmux attach command acts more like a combination of screen -r and screen -x -- first it trys to attach to the most recently detached session, and then if none is available it will attach to a currently attached session. I want to emulate the behavior of screen -R: first try to attach to a detached session, then start a new session if there were no detached sessions. What is the best way to achieve this in tmux?

tmux at will attach to the last session (#1) (even though this session is still attached somewhere else). This ruins the whole idea of running several tmux sessions and attaching only to a detached one (to use mosh + tmux + iterm2 to create a perfect roaming terminal).

The first proposal would attach to currently attached tmux sessions (similar to screen -x), which is something I want to avoid. The second proposal exhibits this same problem and also has the undesirable consequence of creating "extra" tmux sessions when I use the tmux source-file command to reload the config.
–
Drew FrankOct 13 '12 at 21:53