A tmux session manager plugin that allows sessions to be lazily restored in order to save memory and processing power, when compared to other session managers which generally restore all of your sessions at once.
There are already a bunch of tmux session managers, like tmux-resurrect. Why did you make another one?
I've used tmux-resurrect for years and it's an awesome plugin, but I kept running into one major issue. I have a separate tmux session for every project that I work on, which is around 20 different projects. These project-based tmux sessions usually involve running Neovim, LSPs, and other processes. This can eat up a lot of resources and usually I'm only working on one or two of those projects in any given day so loading the rest is a waste.
So I took the next logical step and started working on a PR for tmux-resurrect to add functionality to lazily restore sessions, but then I happened upon these issues on their GitHub page and started having serious doubts as to whether or not my PR would even be considered:
- tmux-resurrect Issue #465 (Closed - Not planned)
- tmux-resurrect Issue #255 (Closed - User found work-around)
So here we are: yet another tmux session manager!
- Lazily Restore Individual Sessions: A custom session-chooser allows selecting any session from the previously saved tmux sessions and only that session will be restored. This can be a huge savings for memory and processing power.
- Save/Update Individual Sessions: You can save new sessions and update individual sessions without impacting all of your other sessions.
- Easy-to-Read JSON Format: Session files are stored in human-readable JSON files and can be updated by hand if so desired.
- Bulk Session Operations: Optionally Save All and/or Restore All sessions at once, similar to other tmux session managers.
- tmux - You can't use tmux plugins without tmux, right?
- fzf - Allows fuzzy finding sessions to restore
DISCLAIMER: I do all of my development on a Debian/Ubuntu based Linux distro, so while this SHOULD still work on other systems, it is geared towards my own dev environment and may not work elsewhere. If you are using a Mac, your mileage may vary (you Kool-Aid-drinking, hipster Apple fanboi). If you are using Windows, I'll see you in Hell!
Installation Using TPM
-
After installing all of the prerequisites, you can add the following to you .tmux.conf file:
set -g @plugin 'bcampolo/tmux-lazy-restore'
-
Start tmux as usual
tmux
prefix + f
- Fuzzy [F]ind a session and if not already loaded, restore the chosen session from the session fileprefix + u
- Save/[U]pdate the current session only to the session fileprefix + r
- [R]evert the current session to its definition in the session fileprefix + X
- Delete/E[X]terminate the current session and remove it from session fileprefix + Ctrl-r
- [R]estore all sessions (NOTE: Does not impact current sessions that don't already exist in the file)prefix + Ctrl-s
- [S]ave all sessions (NOTE: Does not impact sessions in the file that are not currently loaded)
- Add the following to your ~/.tmux.conf file after the line that adds the plugin
set -g @tmux-lazy-restore-choose-key 'f' set -g @tmux-lazy-restore-update-key 'u' set -g @tmux-lazy-restore-revert-key 'r' set -g @tmux-lazy-restore-delete-key 'X' set -g @tmux-lazy-restore-restore-all-key 'C-r' set -g @tmux-lazy-restore-save-all-key 'C-s'
Optionally add the following to your ~/.tmux.conf file after the tmux-lazy-restore plugin line:
- Change the session file path (defaults to ~/.config/tmux-lazy-restore/sessions.json):
set -g @tmux-lazy-restore-session-file '/path/to/file'
- After restoring session(s), kill the tmux session that the restore command was launched from, under the following conditions (defaults to 'off'):
- The launching session was the only session before restoring
- The launching session is empty (1 window, 1 pane)
- The launching session name is numeric (usually auto-named by tmux)
- The launching session is not the active session being restored
set -g @tmux-lazy-restore-kill-launch-session 'on'
- Fuzzy Find and Restore Individual Session
- Save/Update Individual Session
- Restore All Sessions
- Save All Sessions
- Delete Individual Session
- Revert Individual Session
- Indicate which sessions are new and which are already loaded
- Interoperability with tmux-resurrect
If you run into any issues or have any suggestions, open a Pull Request that includes the updates and I'll review/comment/merge it as soon as I can. If you don't have enough time or don't know how to fix the issue, submit an Issue and provide as much detail as you can.
I would like to thank the following plugins for inspiration and as a reference during development: