Save and reopen tmux session

Hi, everyone -

I am new to tux and finally got the panes and splits exactly as I like them for my current Rails project. Is there a way to save this setup so that it starts this way every time start tmux?

Thanks, Hunt

Two of the most popular ways to do this (that I know of) are Tmuxinator and Tmux Resurrect.

With Tmuxinator, you set up yaml files which define predetermined layouts. You can then launch these layouts by running a single command.

Tmux Resurrect (which I prefer) allows you to save your tmux layout, and then “resurrect it” later by pressing a key combo. Tmux Resurrect also supports vim sessions and a few other processes that you might want to respawn after restarting your machine.

The author of Tmux Resurrect has recently released a new plugin called Tmux Continuum which restarts everything automatically. Sounds good, though I’ve not tried it myself yet.

Hope that helps!

1 Like

@joshukraine did a great job summarizing the various options for this, so I will just second everything he said with regard to the tools and workflows for automating tmux session layouts.

The one thing I will add is that while I have used tools like tmuxinator in the past, I no longer use them. I find that my desired layout changes somewhat regularly depending on the task (TDDing out a new feature, tracking down a bug, working with production data, etc) and I value that flexibility.

Beyond that, I’ve optimized and streamlined my workflow around creating and arranging panes such that it is very easy to change the layout on the fly. Check out the Navigation and Vim Integration videos in the tmux trail for tips on this.

@joshukraine – Tmux Resurrect does exactly what I wanted. Thanks for the recommendation.

@christoomey – you rock!

But if I want multiple sessions to save ?

resurrect only saves one.

1 Like

You can just put these functions to build your panes and windows of tmux in your .bash_profile

# 2 right sidebar panes
function tmux-ide-1() {
  tmux split-window -h -p 25
  tmux split-window -v -p 50
}

# 3 bottom sub-panes
function tmux-ide-2() {
  tmux split-window -v -p 30
  tmux split-window -h -p 66
  tmux split-window -h -p 50
}