💾 Archived View for republic.circumlunar.space › users › johngodlee › posts › 2023-09-23-tmux_sessio… captured on 2024-02-05 at 10:21:13. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-09-28)

-=-=-=-=-=-=-

tmux grouped sessions

DATE: 2023-09-23

AUTHOR: John L. Godlee

I have two monitors at work. Normally I have a terminal running tmux open full screen on the right-hand monitor, in portrait, and use the left monitor in landscape for everything else. Occasionally however, I want to also have a terminal open on the left monitor, and to move windows easily between terminals. To make it easier to share windows across terminals, I have adjusted my tmux setup to take advantage of the grouped-sessions feature.

At the bottom of my .tmux.conf I have this chunk, which starts a new session called "main", as a daemon.

new-session -s main -d

Then, at the bottom of my .bashrc I have this chunk. First it checks if tmux is already running (if [ -z "$TMUX" ]). Then if tmux isn't running, it creates a new session within the same group as session "main" (new-session -t main). It then sets the option destroy-unnattached, which removes clients when you detach from them, ensuring that the automatically created sessions don't pile up when they are detached from.

if [ -z "$TMUX" ]; then
    /usr/local/bin/tmux new-session -t main \; set-option destroy-unattached
fi

The result is that when I open a terminal, tmux checks if the "main" session exists, creates it if it doesn't and attaches a client to that session.

All sessions in the same group share the same set of windows, but you can move freely between windows in each session.

{{< video src="/vid/tmux_sessions/tmux_sessions.mp4" >}}