# ~/.acfs/tmux/tmux.conf
# ACFS tmux configuration optimized for NTM and agent workflows

# ============================================================
# Core settings
# ============================================================

# Enable mouse support (essential for beginners)
set -g mouse on

# Set default terminal for proper color support
# tmux-256color enables bracketed paste, styled underlines, and other modern features
# that screen-256color lacks (see tmux FAQ and terminfo docs)
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",*256col*:Tc"
# Allow passthrough sequences (kitty graphics, sixel, etc.) and cursor shape overrides
set -g allow-passthrough on
set -ga terminal-overrides ",*:Ss=\\E[%p1%d q:Se=\\E[2 q"

# Start windows and panes at 1, not 0
set -g base-index 1
setw -g pane-base-index 1

# Renumber windows when one is closed
set -g renumber-windows on

# Increase scrollback buffer size
set -g history-limit 50000

# Reduce escape time (faster key response)
set -sg escape-time 10

# Enable focus events for vim/neovim
set -g focus-events on

# ============================================================
# Key bindings
# ============================================================

# Use Ctrl-a as prefix (more ergonomic than Ctrl-b)
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# Reload config with prefix + r
bind r source-file ~/.tmux.conf \; display-message "Config reloaded!"

# Split panes with intuitive keys
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %

# Navigate panes with vim-style keys
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# Resize panes with vim-style keys
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# Create new window in current directory
bind c new-window -c "#{pane_current_path}"

# ============================================================
# Status bar
# ============================================================

# Position at top (less intrusive)
set -g status-position top

# Status bar colors
set -g status-style "bg=#1e1e2e,fg=#cdd6f4"

# Left side: session name
set -g status-left-length 30
set -g status-left "#[fg=#89b4fa,bold] #S #[default]"

# Right side: date and time
set -g status-right-length 50
set -g status-right "#[fg=#6c7086]%Y-%m-%d %H:%M #[default]"

# Window status
setw -g window-status-format " #I:#W "
setw -g window-status-current-format "#[fg=#f5c2e7,bold] #I:#W #[default]"

# ============================================================
# Copy mode (vim-style)
# ============================================================

setw -g mode-keys vi

# Enter copy mode with prefix + [
# Select text with v, copy with y
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind -T copy-mode-vi r send-keys -X rectangle-toggle

# ============================================================
# Pane styling
# ============================================================

# Pane borders
set -g pane-border-style "fg=#313244"
set -g pane-active-border-style "fg=#89b4fa"

# ============================================================
# Session management (for NTM compatibility)
# ============================================================

# Don't detach when session is destroyed
set -g detach-on-destroy off

# Activity monitoring (useful for agent workflows)
setw -g monitor-activity on
set -g visual-activity off

# ============================================================
# Source local overrides
# ============================================================

if-shell "test -f ~/.tmux.conf.local" "source-file ~/.tmux.conf.local"
