# 基础设置
set -g default-terminal "screen-256color"    # 启用256色支持
set -g terminal-overrides ',xterm-256color:Tc'
set -sg escape-time 0                        # 移除延迟
set -g focus-events on                       # 启用焦点事件
set -g mouse on                              # 启用鼠标
set -g base-index 1                          # 窗口编号从1开始
setw -g pane-base-index 1                    # 面板编号从1开始
set -g renumber-windows on                   # 自动重新编号窗口
set -g history-limit 50000                   # 增加历史记录限制

# 修改前缀键
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# vim风格快捷键
setw -g mode-keys vi
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel

# 窗格分割
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %

# 窗格导航
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# Alt+方向键切换窗格(无需前缀)
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# 调整窗格大小
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

# 状态栏美化
set -g status-position top               # 状态栏置顶
set -g status-interval 1                 # 状态栏刷新时间
set -g status-style bg='#1e1e2e',fg='#cdd6f4'
set -g status-left-length 30
set -g status-right-length 50

# 状态栏格式
set -g status-left '#[fg=#1e1e2e,bg=#89b4fa,bold] #S #[fg=#89b4fa,bg=#1e1e2e]'
set -g status-right '#[fg=#cba6f7,bg=#1e1e2e]#[fg=#1e1e2e,bg=#cba6f7,bold] %Y-%m-%d %H:%M '
setw -g window-status-current-format '#[fg=#1e1e2e,bg=#89b4fa] #I #W #F '
setw -g window-status-format '#[fg=#cdd6f4,bg=#1e1e2e] #I #W #F '

# 窗格边框
set -g pane-border-style fg='#313244'
set -g pane-active-border-style fg='#89b4fa'

# 消息提示
set -g message-style bg='#89b4fa',fg='#1e1e2e'

# 启用活动警告
setw -g monitor-activity on
set -g visual-activity on

# 快速重载配置文件
bind r source-file ~/.tmux.conf \\; display "配置已重新加载!"

# ===== 插件管理 =====
# 插件列表
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'tmux-plugins/tmux-pain-control'
set -g @plugin 'tmux-plugins/tmux-copycat'

# 插件配置
set -g @resurrect-capture-pane-contents 'on'    # 保存面板内容
set -g @resurrect-strategy-vim 'session'        # 保存vim会话
set -g @continuum-restore 'on'                  # 自动恢复上次保存的环境
set -g @continuum-save-interval '15'            # 每15分钟自动保存一次
set -g @yank_selection_mouse 'clipboard'        # 鼠标选中文本时自动复制到系统剪贴板

# 初始化TPM (保持在配置文件的最后一行)
run '~/.tmux/plugins/tpm/tpm'