--- name: trent-tmux description: Help with tmux, tmuxinator, and sesh session management. Use when the user asks about tmux sessions, tmuxinator templates, session switching, or terminal multiplexing. --- # Tmux Session Management Skill ## Overview This system uses tmux with tmuxinator templates and sesh for powerful session management. ## Configuration Locations - **Tmuxinator templates**: `~/.config/tmuxinator/*.yml` - **Tmux config**: `~/.tmux.conf` - **Zsh tmux aliases/functions**: `~/.zshrc` (lines 37-72) - **Active sessions**: Check with `tmux ls` or `sesh list` ## Tmuxinator Templates ### Current Templates 1. **default.yml** - Flexible project template - Takes directory argument: `tmuxinator start default ~/path` - Layout: nvim (top 70%), terminal + claude (bottom) - Dynamic session naming based on directory 2. **admin.yml** - System monitoring - Fixed name: "admin" - Layout: btop (left column), 2 terminals (right) - Purpose: System monitoring and administration 3. **config.yml** - Dotfiles editing - Fixed name: "config" - Root: `~/.config` - Layout: nvim (top 70%), terminal + claude (bottom) ### Template Structure **CRITICAL: Pane Indexing** This tmux configuration uses **1-based indexing** (set in `~/.tmux.conf`): ```tmux set -g base-index 1 # Windows start at 1 set -g pane-base-index 1 # Panes start at 1 ``` - First pane = 1, second = 2, third = 3 - Use `prefix + q` (Ctrl+Space then q) to see pane numbers visually - When targeting panes in commands: `select-pane -t 1` (not -t 0) **Tmuxinator YAML Structure:** ```yaml --- name: session-name # Fixed name (or use <%= File.basename(...) %> for dynamic) root: ~/path # Working directory on_project_start: tmux resize-pane -t name:0.0 -y 70% # Optional startup commands windows: - window-name: layout: main-horizontal # or main-vertical, tiled, even-horizontal, etc. panes: - nvim # Command to run in pane 1 - # empty terminal # Empty pane (interactive shell) - pane 2 - claude --resume # Command for pane 3 ``` **Shell Function Structure (for creating windows dynamically):** ```bash tnw() { # Get the session's root directory (uses 1-based indexing internally) local session_path=$(tmux display-message -p '#{session_path}') tmux new-window -c "$session_path" \; \ split-window -v -c "$session_path" \; \ split-window -v -c "$session_path" \; \ select-layout main-horizontal \; \ select-pane -t 1 \; \ send-keys 'nvim' C-m \; \ select-pane -t 3 \; \ send-keys 'claude --resume' C-m \; \ select-pane -t 2 } ``` **Key points for both:** - Use `#{session_path}` to get session root directory (not current pane path) - Pane indexing is 1-based: first pane = 1, not 0 - `send-keys 'command' C-m` executes commands in panes (C-m = Enter) - `select-pane -t N` focuses pane N (1-based) - `select-layout` applies tmux built-in layouts ### Common Layouts - `main-horizontal` - Top pane large, others stacked below - `main-vertical` - Left pane large, others stacked right - `tiled` - All panes equal size - `even-horizontal` - Panes side-by-side equal width - `even-vertical` - Panes top-to-bottom equal height ## Session Management with `ts` (tmux session selector) The `ts` function (defined in `~/.zshrc`) is the main session switcher: ```bash ts # Opens fzf with: "home" + tmuxinator templates + active sessions ``` ### How `ts` Works 1. Lists all tmuxinator templates (except default.yml) 2. Adds "home" as an option 3. Shows all active tmux sessions from `sesh list` 4. On selection: - If session exists → attach with `sesh connect` - If tmuxinator template exists → `tmuxinator start