Use “Grouped Sessions”
Instead of attaching to a session, you can create a “grouped session” by giving -t
to new-session
:
tmux new-session -t 'original session name or number'
Sessions that are grouped always have the same windows (new (closed) windows are linked into (removed from) all the session in the group), but they each have their own session options, including the current and previous window values.
If you and your friend each work in a session that is part of the the same group, then you can each work in different windows but still have easy access to the same set of windows, or even work in the same window (if that is appropriate).
Example
Create an initial session:
tmux # start initial session, lets say it gets the name '3'
To keep it clear who should use each session, you should will probably want to give each session a mnemonic name. I will use his
and mine
below, but you will probably want to use something based on your real names, nick names, login names, or something else equally identifying.
Rename this original session as his
and (outside of the original session) create a grouped session named mine
:
tmux rename-session -t 3 his
tmux new-session -d -t his -s mine # leave off -d to attach right away
When you want to attach to your clone of “the session”:
tmux attach-sesssion -t mine
When your friend wants to attach to his clone of “the session”:
tmux attach-session -t his
You can kill-session
either session and the other will survive. You have to kill all of the sessions in a group before their windows will be forcibly closed.
tmux Command Abbreviations
If you are scripting the tmux commands, it is probably best to use the full command names (as above) to avoid ambiguity and aid in “self documentation”. If you are typing them you can use abbreviations:
new-session
: new
, or new-s
, new-se
, new-ses
, …
rename-session
: rename
, or rename-s
, rename-se
, rename-ses
, …
attach-session
: a
, at
, …, attach
, attach-
, attach-s
, …
kill-session
: kill-ses
, kill-sess
, …