# Config.
unbind-key C-b
set-option -g prefix C-[
bind-key C-[ send-prefix
bind -n M-r source-file ~/.config/tmux/tmux.conf

# Copy.
setw -g mode-keys vi
bind -n M-v copy-mode
bind -n M-p choose-buffer;
bind -T copy-mode-vi v send      -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"

# Env.
set -sg escape-time 0
set-option -g default-terminal "tmux-256color"
set-option -g focus-events on
set-option -sa terminal-features "RGB"
set -g allow-passthrough on
set-option -g update-environment "SSH_CLIENT SSH_TTY DOCKER_CONFIG DOCKER_HOST DISPLAY XAUTHORITY BASH_PATH SWAY_SOCK TERM TERM_PROGRAM"

# Scroll.
bind -n M-K copy-mode -u
bind -n M-J send-keys Pagedown

# Session.
bind -n M-z detach-client
bind -n M-Z detach-client -a
bind -n M-, switch-client -p
bind -n M-. switch-client -n
bind -n M-g choose-session -Z
set -g window-size smallest

# Split.
bind -n M-\\ split-window  -h -c "#{pane_current_path}"
bind -n M--  split-window  -v -c "#{pane_current_path}"
bind -n M-=  select-layout tiled
bind -n M-_  select-layout even-vertical
bind -n M-|  select-layout even-horizontal
bind -n M-+  select-layout main-vertical
bind -n M-k  resize-pane -U 1
bind -n M-j  resize-pane -D 1
bind -n M-h  resize-pane -L 1
bind -n M-l  resize-pane -R 1
bind -n M-A  swap-pane   -U
bind -n M-W  swap-pane   -U
bind -n M-D  swap-pane   -D
bind -n M-S  swap-pane   -D
unbind '"'
unbind %
bind -n M-a select-pane -L
bind -n M-d select-pane -R
bind -n M-w select-pane -U
bind -n M-s select-pane -D
bind -n M-c kill-pane
bind -n M-C kill-pane -a

# Status.
bind-key -n M-f set-option -g status;
set -g status-left-length 50
set -g status-position bottom
set -g status-justify  left
set -g status-left "#[bold] #H-#S #[default]"
set -g status-right ""
set-window-option -g window-status-separator ""
setw -g window-status-current-format " #W "
setw -g window-status-format " #W "
set-window-option -g visual-bell off
setw -g window-status-bell-style "bold blink"

# Style.
set -g mode-style "fg=#@fg@ bg=#@bg@ bold"
setw -g window-status-current-style "fg=#@accent@ bold"
setw -g window-status-style ""
set -g pane-border-style        "fg=#@bg@"
set -g pane-active-border-style "fg=#@accent@"
set -g status-style "fg=#@fg@"
set -g menu-style          "fg=#@fg@"
set -g menu-selected-style "fg=#@fg@ bg=#@bg@ bold"
set -g menu-border-style   "fg=#@bg@"
set -g popup-style        "fg=#@fg@"
set -g popup-border-style "fg=#@bg@"
set -g display-panes-colour        "#@bg@"
set -g display-panes-active-colour "#@accent@"
set -g copy-mode-position-style  "fg=#@selectionBg@ bg=#@selectionFg@ bold"
set -g copy-mode-selection-style "fg=#@selectionFg@ bg=#@selectionBg@ bold"

# Window.
bind -n M-Escape new-window -c "#{pane_current_path}"
bind -n M-t      new-window -c "#{pane_current_path}"
bind -n M-x kill-window
bind -n M-X kill-window -a
bind -n M-e next-window
bind -n M-q previous-window
bind -n M-E swap-window -t +1\; select-window -t +1
bind -n M-Q swap-window -t -1\; select-window -t -1