diff --git a/systemd/README.md b/systemd/README.md new file mode 100644 index 0000000..fec87aa --- /dev/null +++ b/systemd/README.md @@ -0,0 +1,47 @@ +# Systemd Timer for tmux-resurrect Auto-Save + +An alternative to the default `status-right` based auto-save that uses a systemd user timer instead. + +## Why? + +The default auto-save mechanism uses `#()` command substitution in tmux's `status-right`. This command runs on every status bar refresh for every attached client. With many sessions and clients, this can cause significant CPU overhead. + +A systemd timer runs the save script once per interval, regardless of the number of sessions or clients. + +## Setup + +Copy the unit files to your systemd user directory: + +```bash +cp systemd/tmux-resurrect-save.service ~/.config/systemd/user/ +cp systemd/tmux-resurrect-save.timer ~/.config/systemd/user/ +``` + +Adjust the path in the service file if your tmux-resurrect is installed somewhere other than `~/.tmux/plugins/tmux-resurrect/`. + +Enable and start the timer: + +```bash +systemctl --user daemon-reload +systemctl --user enable --now tmux-resurrect-save.timer +``` + +Then disable the status-right based auto-save in your `tmux.conf`: + +```tmux +set -g @continuum-save-interval '0' +``` + +## Verify + +Check the timer status: + +```bash +systemctl --user list-timers | grep tmux +``` + +Manually trigger a save: + +```bash +systemctl --user start tmux-resurrect-save.service +``` diff --git a/systemd/tmux-resurrect-save.service b/systemd/tmux-resurrect-save.service new file mode 100644 index 0000000..cd41412 --- /dev/null +++ b/systemd/tmux-resurrect-save.service @@ -0,0 +1,6 @@ +[Unit] +Description=Auto-save tmux sessions via tmux-resurrect + +[Service] +Type=oneshot +ExecStart=/bin/bash -c 'if tmux info &>/dev/null; then "$HOME/.tmux/plugins/tmux-resurrect/scripts/save.sh" quiet; fi' diff --git a/systemd/tmux-resurrect-save.timer b/systemd/tmux-resurrect-save.timer new file mode 100644 index 0000000..c6298f9 --- /dev/null +++ b/systemd/tmux-resurrect-save.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Auto-save tmux sessions every 15 minutes + +[Timer] +OnBootSec=5min +OnUnitActiveSec=15min + +[Install] +WantedBy=timers.target