Mastodon hachyterm.io

You’ve created a tmux session and worked with it. You’ve created a pane layout that works for you, and started your Vim editor.

What happens when you shut down your computer, and start it again later?

Tmux doesn’t remember your sessions. When you restart tmux, you loose all your running programs, etc.

There are two tmux plugins that can help with that: Tmux Resurrect and tmux-continuum.

Installation with Tmux Plugin Manager

Add theses lines to the list of plugins inside tmux.conf:

set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'

Extra Features

You can add some extra functionality to tmux.conf:

## Restore Vim sessions
set -g @resurrect-strategy-vim 'session'
## Restore Neovim sessions
set -g @resurrect-strategy-nvim 'session'
## Restore Panes
set -g @resurrect-capture-pane-contents 'on'
## Restore last saved environment (automatically)
set -g @continuum-restore 'on'

Start tmux Automatically on Boot

OSX

Add this line to tmux.conf:

set -g @continuum-boot 'on'

You can find more information about this feature on GitHub.

Linux

The script only works with systemd.

Add this line to tmux.conf:

set -g @continuum-boot 'on'

Exit tmux, and reload with tmux source-file ~/.tmux.conf.

You’ll find a new service file under ~/.config/systemd/user/tmux.service.

[Unit]
Description=tmux default session (detached)
Documentation=man:tmux(1)

[Service]
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/tmux new-session -d

ExecStop=/home/owlhoot/.tmux/plugins/tmux-resurrect/scripts/save.sh
ExecStop=/usr/bin/tmux kill-server
KillMode=none

RestartSec=2

[Install]
WantedBy=default.target

Copy the file to etc/systemd/system. You’ll need sudo for that.

sudo cp ~/.config/systemd/user/tmux.service /etc/systemd/system/

Enable the service:

sudo systemctl enable tmux --now