Tmux: Set default session for attach

tmux

I have two tmux sessions (0 and 1), each with a set of windows. When I run tmux a, I attach to one of the two sessions, usually 1 but sometimes 0. I always want to attach to 0 if I don't specify a target-session.

I've been looking through the manpage and have found the following:

tmux a -t 0 – Specify session 0 explicitly. I'd rather set 0 as the default session and avoid specifying an argument.

If a session is omitted, the current session is used if available; if
no current session is available, the most recently used is chosen.

There is no current session (because there are no clients attached yet), and the "most recently used" does not seem to apply: I can detach from session 0 but when I reattach I end up on session 1. This seems to be time-sensitive; if I detach and reattach very quickly, I return to session 0, but if I wait even 1 second, I attach to session 1.

Of course, I can create a shell alias for tmux a -t 0 and use that if there's no way to set a default attach session. I could also swap the windows between sessions so that the ones I want are in session 1 instead of 0. Both of these feel like workarounds that I hoped would be unnecessary.

I am running tmux 1.3-2+squeeze1.

Best Answer

It is time sensitive.

From the man page:

The target-session rules for attach-session are slightly adjusted: if tmux needs to select the most recently used session, it will prefer the most recently used unattached session.

Your shell alias is the way to go for this, it is not a workaround, but the way Unix/Linux works. Small tools to do small things to produce great results.

Related Question