How to reuse sessions in tmux?

Hello Friends

I use tmux. Just being curious

If you want reuse N sessions from one laptop to other, according the case with:

  • Many Windows and Panes (with their respective layout)
  • And keeping for each Pane the current directory where is located

How is possible accomplish this goal?

I already did do a research in Google but it seems is not possible but perhaps you have an β€œapproach” For example about Terminator I reuse some content of the hidden configuration file

Thank You

1 Like

You can save X sessions, within one laptop.
To transfer these to another laptop, the two laptops would need to share the one .Xsession file. or you would need to copy the file across to the other laptop.
I think it would require both laptops to have the same DE.
I know Xfce can session save both automatically and manually. Do not know about other DE’s

Sorry, I dont know anything about tmux sessions, but tmux runs under X so saving X sessions would save tmux sessions.
You might be able to share tmux sessions if you can identify the files where they are stored.

2 Likes

As usual, thanks for the reply

I have no problem with that. Is possible use ssh in peace.
But to accomplish your suggestion is mandatory save the session itself. Am I correct? I am going to research about that

I think it would require both laptops to have the same DE.

Well it is for Ubuntu, Fedora and Debian … all working with GNome

Interesting the mentioned constraint

1 Like

Yes. I think you will have to identify the session file(s) and transfer them to the other computer.
In Xorg the session file is called .Xsession and it is in your home directory.
In tmux, I dont know the files, but there must be session files if it can save sessions.

2 Likes

Thanks for the guidance :+1:

2 Likes

tmux doesn’t really run under X… e.g. I run tmux ALL the time e.g. on my FreeBSD NAS (which is not running X or any DE), and Linux (headless) SSH jumphosts (it’s vital sometimes - e.g. I need to know some long running job will continue to run if I lose my session - tmux is the best way I know how).

It can get confusing but - you can join an existing tmux session - i.e. multiple connections to the same tmux session…

e.g. I’m running tmux sesssion called β€œDLZ” on my FreeBSD (TrueNAS) system…
To connect to it - I ssh to my FreeBSD system β€œbaphomet”, from a Linux or MacOS terminal session and type β€œtmux a -t DLZ” : tmux is aware one of my terminal windows is a different aspect ratio/ size and reacts accordingly :

GnomeTerminal (on Pop!_OS) remote tmux session :

iTerm2 (on MacOS) remote tmux session (the SAME session) :

There are some terminals that know about tmux, but I don’t think Gnome Terminal or iTerm2 are specifically β€œtmux aware”… I seem to remember something called β€œbyobu” that was a graphical terminal app for Linux and also a tmux session manager… I don’t use it - tmux on its own is enough…

β€œtmux” is an alternative to the ancient β€œscreen” utility - but its configuration and startup is less β€œobscure” or β€œobtuse” than β€œscreen”…

You can list running tmux sessions β€œtmux ls”…

4 Likes

OK, my lack of knowledge there

@Manuel_Jordan … maybe my X session saving idea was not appropriate.? Sorry if I misled you.
Anyway, tmux must have session files and you should be able to export them.

2 Likes

Dan

Huge thanks for the reply

e.g. I’m running tmux sesssion called β€œDLZ” on my FreeBSD (TrueNAS) system…
To connect to it - I ssh to my FreeBSD system β€œbaphomet”, from a Linux or MacOS terminal session and type β€œtmux a -t DLZ ” : tmux is aware one of my terminal windows is a different aspect ratio/ size and reacts accordingly

Again the importance to work with SSH too

Thanks for the clarification. So you reuse the session created in your server through 2 ssh connections for your clients. Ok it is clear. To be honest I do that.

Let me do a reformulation of my situation in the following way: In your server you have one or many tmux sessions with windows and panes with their respective layouts as you wish …

Later you have detected a problem in your SSD and is mandatory reinstall all the OS in the new SSD …

  • How do you would reuse all the sessions (I mean windows and panes keeping the same layouts)?

It to avoid yourself to re-create all the structure (windows, panes + layouts) from the scratch

There are some terminals that know about tmux, but I don’t think Gnome Terminal or iTerm2 are specifically β€œtmux aware”… I seem to remember something called β€œbyobu” that was a graphical terminal app for Linux and also a tmux session manager… I don’t use it - tmux on its own is enough…

I am not sure if I am in the wrong channel but is possible re-attach to a session from any kind of terminal such as either Terminator or Kitty

β€œtmux” is an alternative to the ancient β€œscreen” utility - but its configuration and startup is less β€œobscure” or β€œobtuse” than β€œscreen”…

Interesting. I did not know about β€œscreen”

p.d: Is your first figure took from pop os? It has the same 3 circles and colors as macOS too

To all

For your consideration it because has windows and panes with custom layouts (it is on my β€œtodo” list yet):

Nevi

… maybe my X session saving idea was not appropriate.? Sorry if I misled you.
Anyway, tmux must have session files and you should be able to export them.

Do not worry. Perhaps for the mentioned β€œreformulation” situation it would be the solution

2 Likes

You can script a tmux sesssion - I used to - but I mostly just do it manually these days…

Here’s a shell script I wrote some time ago (but no longer use regularly) :

╭─x@titan ~/bin  β€Ήmain*β€Ί 
β•°β”€βž€  bat yoyo.bash 
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       β”‚ File: yoyo.bash
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   β”‚ #!/usr/bin/env bash 
   2   β”‚ tmux new-session -s "YOYO" -d
   3   β”‚ tmux split-window -v
   4   β”‚ tmux split-window -v
   5   β”‚ tmux -2 attach-session -d 
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Hmmm - I might start using that script again - I’d forgotten I wrote it :smiley:

Saves me some time - I usually start similar manually, i.e. β€œtmux new -s YOYO” - then β€œCtrl+B+"” and then same again (i.e. 2 x β€œCtrl+B+"”)… The above script does the samething automagically :smiley:


I’ve got another script I use on FreeBSD (TrueNAS) - it checks if there’s a session already - otherwise it starts it off β€œanew” :

───────┬────────────────────────────────────────────────────────────────────────────────────────────────────
       β”‚ File: /home/x/bin/bapmux
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────
   1   β”‚ #!/bin/bash
   2 + β”‚ HOHO=$(uname -n)
   3   β”‚ EXIST=`tmux ls |grep -c DLZ`
   4   β”‚ if [ $EXIST -gt 0 ] ; then 
   5   β”‚     tmux a -t DLZ
   6   β”‚ else
   7   β”‚     tmux new -s DLZ
   8   β”‚ fi
───────┴───────────────────────────────────────────────────────────────────────────────────

I should add that checking bit to my yoyo.bash script…

1 Like