# ============================================================================ # Tmux Workspace Manager - Project Templates & Layouts # ============================================================================ # Enhanced with optional tmuxinator integration for complex projects. # # Simple templates (.tmux files) for quick layouts # Tmuxinator (optional) for full project configurations with commands # # Priority: tmuxinator project > simple template > create new # ============================================================================ source "${0:A:h}/../lib/bootstrap.zsh" 2>/dev/null || \ source "$HOME/.dotfiles/zsh/lib/bootstrap.zsh" 2>/dev/null # ============================================================================ # Configuration # ============================================================================ typeset -g TW_TEMPLATES="${TW_TEMPLATES:-$HOME/.dotfiles/.tmux-templates}" typeset -g TW_PREFIX="${TW_PREFIX:-work}" typeset -g TW_DEFAULT="${TW_DEFAULT:-dev}" # Tmuxinator integration (auto-detect if available) typeset -g TW_USE_TMUXINATOR="${TW_USE_TMUXINATOR:-auto}" typeset -g TMUXINATOR_CONFIG_DIR="${TMUXINATOR_CONFIG_DIR:-$HOME/.config/tmuxinator}" # ============================================================================ # Internal Functions # ============================================================================ _tw_check() { df_require_cmd tmux || return 1; } _tw_has_tmuxinator() { [[ "$TW_USE_TMUXINATOR" == "false" ]] && return 1 command -v tmuxinator &>/dev/null } _tw_tmuxinator_project_exists() { [[ -f "$TMUXINATOR_CONFIG_DIR/${1}.yml" ]] } _tw_init() { df_ensure_dir "$TW_TEMPLATES" # Create default templates if they don't exist [[ ! -f "$TW_TEMPLATES/dev.tmux" ]] && { cat > "$TW_TEMPLATES/dev.tmux" << 'EOF' # Development workspace # Layout: Editor (50%) | Terminal (25%) / Logs (25%) split-window -h -p 50 split-window -v -p 50 select-pane -t 0 EOF cat > "$TW_TEMPLATES/ops.tmux" << 'EOF' # Operations workspace - 2x2 grid split-window -h -p 50 split-window -v -p 50 select-pane -t 0 split-window -v -p 50 select-pane -t 0 EOF cat > "$TW_TEMPLATES/full.tmux" << 'EOF' # Full screen - single pane (default) EOF cat > "$TW_TEMPLATES/review.tmux" << 'EOF' # Code review - side by side split-window -h -p 50 select-pane -t 0 EOF cat > "$TW_TEMPLATES/debug.tmux" << 'EOF' # Debug workspace - main (70%) + helper (30%) split-window -h -p 30 select-pane -t 0 EOF cat > "$TW_TEMPLATES/ssh-multi.tmux" << 'EOF' # Multi-server SSH - 4 panes with sync option split-window -h -p 50 split-window -v -p 50 select-pane -t 0 split-window -v -p 50 # Uncomment to enable synchronized input: # set-window-option synchronize-panes on select-pane -t 0 EOF df_print_success "Created default templates in $TW_TEMPLATES" } } # ============================================================================ # Template Functions # ============================================================================ tw-templates() { _tw_init df_print_func_name "Workspace Templates" echo "" df_print_section "Simple Templates (.tmux)" for t in "$TW_TEMPLATES"/*.tmux(N); do [[ -f "$t" ]] || continue local name=$(basename "$t" .tmux) local desc=$(head -1 "$t" | sed 's/^#[[:space:]]*//') df_print_indent "● $name" [[ -n "$desc" ]] && df_print_indent " └─ $desc" done if _tw_has_tmuxinator; then echo "" df_print_section "Tmuxinator Projects" local found=false for p in "$TMUXINATOR_CONFIG_DIR"/*.yml(N); do [[ -f "$p" ]] || continue found=true local name=$(basename "$p" .yml) df_print_indent "● $name (tmuxinator)" done [[ "$found" != true ]] && df_print_indent "(none - create with txi-new)" fi echo "" df_print_info "Create workspace: tw-create