I've run into an odd situation with tmux just now, and I'm not sure if it's a bug, or (more likely) something that I did by accident:
I have two sessions:
foo-0
foo-1
Attaching to them with tmux attach-session -t foo-[0/1]
works, but I see the same thing in both cases. Changes made to one session (closing a pane, running commands, etc) apply to the other.
I created a new session with tmux new-session -t bar
, and that produced a new session which shares nothing with the first two.
What causes this behavior, and how do I "consolidate" my two sessions into one without losing both of them?
Best Answer
It's not a bug.
In tmux you can link any window to multiple sessions. In effect you can have two (or more) sessions with exactly the same set of windows in the same order. In such case the sessions look the same. There are two possibilities:
Either you created two separate sessions and then linked (
link-window
) and arranged (move-window
) windows, so the sessions look the same. I think it's hard to do this by accident, so probably this is not what happened.Or you created two sessions in the same session group. It's very easy to do this if you use
new-session -t
instead ofnew-session -s
. Your question makes me believe you used-t
when you meant-s
. The rest of my answer investigates this possibility.This is the relevant part of
man 1 tmux
:My hypothesis is you wanted to create a new session with name
foo
. You mistook-t
for-s
and instead oftmux new-session -s foo
you invokedHere
foo
is the name for a new group. You did not providesession-name
. Mytmux
in such circumstances names the new sessionfoo-N
and assigns it to the new groupfoo
.N
is0
if it's the very first session within the tmux server. I think this way you gotfoo-0
.Then you forgot about this session and invoked again:
Here
foo
is the name of an existing group. You did not providesession-name
this time either. The tool named the new sessionfoo-1
.In effect the two sessions are in the same session group, they behave like the manual states. If you're not familiar with session groups then it's easy to interpret them as one session that appears twice with different names.
Kill all the grouped sessions but one. In your case
should work. Usually killing a session kills its windows (so also panes in these windows); but any window that is linked to a session that survives will survive. Windows linked to a session belonging to a session group are linked to all sessions belonging to the group. So only killing the last session standing in the group actually kills its windows.
You may want to make sure the sessions in question are truly in the same session group before you kill any session. In general it may be they share some windows but not all of them; or they just look alike. Invoke
This will provide you information about session groups (if any). I expect both sessions (
foo-0
andfoo-1
) will report(group foo)
. This shows they belong to the same session group. You can request a custom format (-F
) or even query for the session group of a particular session. In your case: