tmux state management, how to i save my workspace setup to survive shutdown? | To manage and save your tmux workspace setup so it survives system shutdowns or logouts, you can utilize tmux-resurrect and tmux-continuum, which are plugins for tmux that handle session saving and restoring:
Step-by-Step Guide:
-
Install Tmux Plugin Manager:
First, you'll need the Tmux Plugin Manager (TPM) which simplifies the installation of tmux plugins:
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
Then, you need to add some lines in your .tmux.conf to initialize TPM:
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'git@github.com/user/plugin'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run -b '~/.tmux/plugins/tpm/tpm'
-
Install tmux-resurrect:
Add tmux-resurrect to your .tmux.conf :
set -g @plugin 'tmux-plugins/tmux-resurrect'
-
Save and Restore Sessions:
-
Save your tmux session: Press Prefix + Ctrl-s (where Prefix is commonly Ctrl-b ). This command will save your panes, windows, programs like vim or ssh sessions, and their respective states.
-
Restore a session: Normally, this is automatically done at tmux start due to tmux-continuum , but you can manually trigger it with Prefix + Ctrl-r .
Here, Prefix is whatever prefix key you have set in tmux, typically Ctrl-b .
-
Install tmux-continuum (for automated backups):
Add:
set -g @plugin 'tmux-plugins/tmux-continuum'
For automatic session restore after tmux starts, enable the following settings:
# Turn on automatic restore of tmux session
set -g @continuum-restore 'on'
This should also be in your .tmux.conf . With this setting, tmux-continuum will restore your last session automatically if tmux starts up.
-
Set Interval for Auto Saves:
If you want tmux to automatically save your session every so often (e.g., every 15 minutes), you can adjust the continuum save interval:
set -g @continuum-save-interval '15'
-
Install Plugins:
After adding these lines to your .tmux.conf , install the plugins by:
- Entering tmux (
tmux command in terminal).
- Press
Prefix + I (capital i) to fetch and install the plugins.
With these steps, your tmux sessions, windows, panes, and even terminal programs within them should survive a system shutdown or tmux server crash, and will automatically restart when you start tmux again. Remember to configure your tmux server to persist even when no sessions are attached if you're concerned about long-running processes (you might need to tweak tmux startup scripts or parameters). |