I’ve been a big fan of tmux since I started using it in 2014. I use it locally for multiplexing my terminal, and in combination with mosh it’s also fantastic for work on remote servers. My main issue with it is losing my sessions when a box restarts. Luckily there’s plugins for tmux that solve this problem!
Prerequisites
- tmux (
brew install tmux
on OS X) - TPM (tmux plugin manager). See https://github.com/tmux-plugins/tpm#installation for installation instructions.
Setup
There are two plugins I recommend: tmux-resurrect and tmux-continuum. tmux-resurrect
enables saving and restoring tmux sessions manually, while tmux-continuum
saves automatically and allows for automatically restoring from the last save when tmux is started. To enable these settings, add the following to your ~/.tmux.conf
:
1 2 3 4 |
set -g @plugin 'tmux-plugins/tmux-resurrect' set -g @plugin 'tmux-plugins/tmux-continuum' set -g @continuum-restore 'on' |
Usage
With this configuration, there’s no need to do anything manually. Your tmux sessions will be automatically saved every 15 minutes and automatically restored when tmux is started (e.g. after a reboot). You can manually save with prefix-Ctrl-s
and manually restore with prefix-Ctrl-r
if desired.
Note that this won’t restore running applications. tmux-resurrect
has an optional configuration for doing so, but I’ve left this off for the time being.