The WezTerm Session Manager is a Lua script enhancement for WezTerm that provides functionality to save, load, and restore terminal sessions. This tool helps manage terminal sessions, its goal is to save and restore different sessions or better workspaces and later restore them.
- Save Session State Captures the current layout of windows, tabs and panes, along with their working directories and foreground processes.
- restore Session Reopens a previously saved session that matches the current workspace name, restoring its layout and directories.
- Load Session (Not implemented yet) Allows selecting which saved session to load, regardless of the current workspace name.
-
Clone the Repository Clone the Repository into your WezTerm configuration directory:
git clone https://github.com/danielcopper/wezterm-session-manager.git ~/.config/wezterm/wezterm-session-manager
-
Configure WezTerm: Edit your 'wezterm.lua' file to include the Session Manager:
local session_manager = require("wezterm-session-manager/session-manager")
-
Setup Event Bindings: Edit your 'wezterm.lua' to include the event bindings to trigger the functions of the session manager
wezterm.on("save_session", function(window) session_manager.save_state(window) end) wezterm.on("load_session", function(window) session_manager.load_state(window) end) wezterm.on("restore_session", function(window) session_manager.restore_state(window) end)
-
Set Keybindings: Define Keybindings in your 'wezterm.lua' for saving, restoring and loading sessions:
local wezterm = require 'wezterm'; return { keys = { {key = "S", mods = "LEADER", action = wezterm.action{EmitEvent = "save_session"}}, {key = "L", mods = "LEADER", action = wezterm.action{EmitEvent = "load_session"}}, {key = "R", mods = "LEADER", action = wezterm.action{EmitEvent = "restore_session"}}, }, }
-
I also recommend to set up a keybinding for creating named workspaces as explained here. This helps managing and switching states.
There are currently some limitations and improvements that need to be implemented:
- The script does not restore the state of running applications within each pane (except nvim on linux which seems to work fine but the general handling should be improved)
- It' primarily tested on Linux and Windows, expect some bugs or adjustements that need to be made
- Complex pane layouts won't be correctly restored, the current implementation to determine the pane position is extremely basic
Feedback, bug reports, and contributions to enhance the script are welcome.