A tmux plugin for managing session layouts.
- Add to your
~/.tmux.conf:
set -g @plugin 'juancruzfl/tmux-layouts'-
Press
prefix + Ito install -
Reload tmux config:
tmux source-file ~/.tmux.conf- Clone the repository:
git clone https://github.com/juancruzfl/tmux-layouts ~/.tmux/plugins/tmux-layouts- Add to your
~/.tmux.conf:
run-shell ~/.tmux/plugins/tmux-layouts/tmux-layouts.tmux- Reload tmux config:
tmux source-file ~/.tmux.confCheck that the hook is registered:
tmux show-hooks -g | grep after-new-sessionShould output:
after-new-session run-shell '/path/to/tmux-layouts/scripts/session-init.sh #{session_name}'
Create a session layout:
tmux new -s devThe plugin will:
- Look for a predefined layout at
~/.tmux/plugins/tmux-layouts/layouts/dev.sh - Or look for a saved layout at
~/.tmux-layouts/dev.sh - Or create a new default layout if neither exists
Save your current session layout:
# Press: prefix + Shift+S (hold Shift and press S)Note: Lowercase s (prefix + s) is tmux's built-in session tree viewer and is NOT used by this plugin.
Your layout will be saved to ~/.tmux-layouts/<session-name>.sh
Customize the save keybinding in your ~/.tmux.conf:
# Use a different key
unbind S
bind-key C run-shell "bash ~/.tmux/plugins/tmux-layouts/scripts/layout-state.sh"
# Or use without prefix (just Ctrl+s)
bind-key -n C-s run-shell "bash ~/.tmux/plugins/tmux-layouts/scripts/layout-state.sh"Create predefined layouts in ~/.tmux/plugins/tmux-layouts/layouts/:
#!/usr/bin/env bash
# Layout: dev
# Development environment
# Window 1: Code editor
tmux rename-window -t "$SESSION_NAME:0" "editor"
tmux send-keys -t "$SESSION_NAME:0" "nvim ." C-m
tmux split-window -t "$SESSION_NAME:0" -h -p 30
tmux send-keys -t "$SESSION_NAME:0.1" "git status" C-m
# Window 2: Servers
tmux new-window -t "$SESSION_NAME" -n "servers"
tmux send-keys -t "$SESSION_NAME:servers" "npm run dev" C-m
# Return to editor
tmux select-window -t "$SESSION_NAME:0"Save this as ~/.tmux/plugins/tmux-layouts/layouts/dev.sh and make it executable:
chmod +x ~/.tmux/plugins/tmux-layouts/layouts/dev.shNow tmux new -s dev will automatically load this layout!
To test the plugin without affecting your main tmux configuration, use the included sandbox environment:
- Clone the repository:
git clone https://github.com/juancruzfl/tmux-layouts ~/projects/tmux-layouts
cd ~/projects/tmux-layouts- Start a sandbox tmux session:
tmux -L sandbox -f test/test.conf new-session -s "plugin-test"The -L sandbox flag creates an isolated tmux server that won't interfere with your main tmux sessions. Ensure the paths in the test.conf file keybindings match your current testing enviroment.
The test/test.conf file provides:
- Visual indicators: Yellow status bar shows you're in TEST MODE
- Debug keybindings:
prefix + H- Show registered hooksprefix + M- Show tmux messagesprefix + D- Show debug logprefix + r- Reload test config
- Quick test layouts:
prefix + 1- Create simple 2-pane layoutprefix + 2- Create 3-pane layoutprefix + 3- Create 4-pane layout
# 1. Start sandbox session
tmux -L sandbox -f test/test.conf new-session -s "my-test"
# 2. Inside the session:
# - Press prefix + 1 to create a test layout
# - Press prefix + Shift+S to save the layout
# - Press prefix + L to list saved layouts
# - Press prefix + H to verify hooks
# 3. Test layout restoration
# - Exit the session (type 'exit' or press Ctrl+d)
# - Recreate it: tmux -L sandbox -f test/test.conf new-session -s "my-test"
# - Your layout should be restored!
# 4. Clean up when done
tmux -L sandbox kill-server
rm -rf ~/.tmux-layouts-testThe test environment includes example layouts in layouts/:
# Test the dev layout
tmux -L sandbox -f test/test.conf new-session -s "dev"
# Test the simple layout
tmux -L sandbox -f test/test.conf new-session -s "simple"- Check hook is set:
tmux show-hooks -g | grep after-new-session- Verify permissions:
ls -la ~/.tmux/plugins/tmux-layouts/tmux-layouts.tmux
# Should show: -rwxr-xr-x (executable)- Check tmux messages for errors:
tmux show-messages- Manually test the init script:
bash -x ~/.tmux/plugins/tmux-layouts/scripts/session-init.sh devThis means the script file can't be found. Check:
ls -la ~/.tmux/plugins/tmux-layouts/scripts/layout-state.sh
# Verify the file exists and is executable
chmod +x ~/.tmux/plugins/tmux-layouts/scripts/layout-state.sh
# Make it executable if neededIf pressing prefix + s shows the session tree instead of saving:
- You're using lowercase
sinstead ofShift+S - Press
prefixthen holdShiftand pressS
The test environment uses -L sandbox to create a separate tmux server. If you're having issues:
# Kill the sandbox server
tmux -L sandbox kill-server
# Your main tmux sessions are unaffected
tmux ls # Shows your normal sessionsContributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Test your changes using the sandbox environment:
tmux -L sandbox -f test/test.conf new-session -s "test-feature"- Submit a pull request