Save and restore tmux pane layouts per directory
- Shell 100%
This adds selectable built-in default layouts via `-D0` and `-D1`, saves them only when a directory has no existing layout, and applies the chosen layout immediately so new projects can be bootstrapped with a consistent pane setup. |
||
|---|---|---|
| README.md | ||
| tmsave.sh | ||
tmsave
Save and restore tmux pane layouts per directory.
Installation
Source the script in your shell config:
source /path/to/tmsave.sh
Dependency: jq (for JSON parsing on restore)
Usage
Save layout
cd ~/myproject
# Set up your panes how you like them
tmsave
Save a built-in default layout
tmsave -D # D0: current 3-pane default
tmsave -D1 # D1: 4-pane default, with the right column split
tmsave -D1 ~/myproject
Default layouts are only saved when no layout exists for that directory, and are applied immediately.
Restore layout
cd ~/myproject
tmre
Apply layout from another directory (git worktrees)
Pass a directory to load its layout and apply it to your current directory. Subdirectory panes are mapped relatively.
# You have a layout saved for your main worktree
cd ~/myproject-feature-branch
tmre ~/myproject
# Pane that was at ~/myproject/ui → opens at ~/myproject-feature-branch/ui
List saved layouts
tmlist # Human-readable table
tmlist --json # JSON array for scripting
Move layout to new path
When you relocate a project:
tmsavemv ~/old/path ~/new/path
Help
All commands support -h / --help:
tmsave --help
tmre --help
tmlist --help
tmsavemv --help
How it works
- Layouts are stored in
~/.local/share/tmsave/layouts/ - Indexed by base64-encoded directory path
- Saves: pane geometry, subdirectory paths, active pane
- Restores: recreates panes, applies layout,
cds into subdirectories only where needed
Notes
- Run
tmsavefrom the project root directory - Panes in subdirectories are restored with relative
cd - Panes outside the base directory stay at the base on restore (warning shown on save)