# improve colors
# set -g utf8
# set-window-option -g utf8 on

# Add truecolor support
set-option -ga terminal-overrides ",xterm-256color:Tc"
# Default terminal is 256 colors
set -g default-terminal "screen-256color"

set -s escape-time 0

# act like vim
setw -g mode-keys vi
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind-key -r C-h select-window -t :-
bind-key -r C-l select-window -t :+

set -g prefix2 C-a
bind-key -n C-b send-prefix

# start window numbers at 1 to match keyboard order with tmux window order
set -g base-index 1
set-window-option -g pane-base-index 1

# renumber windows sequentially after closing any of them
set -g renumber-windows on

# soften status bar color from harsh green to light gray
set -g status-bg '#666666'
set -g status-fg '#aaaaaa'

# remove administrative debris (session name, hostname, time) in status bar
set -g status-left ''
set -g status-right ''

# increase scrollback lines
set -g history-limit 10000

# prefix -> back-one-character
bind-key C-b send-prefix
# prefix-2 -> forward-incremental-history-search
bind-key C-s send-prefix -2

set -g mouse on

# if-shell "uname | grep -q Darwin" "source-file ~/.dotfiles/tmux-osx.conf"

set-option -g default-shell /bin/zsh

# Bind ']' to use pbpaste
bind ] run "reattach-to-user-namespace pbpaste | tmux load-buffer - && tmux paste-buffer"

bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-selection
bind-key -T copy-mode-vi H send-keys -X start-of-line
bind-key -T copy-mode-vi L send-keys -X end-of-line
bind-key -T choice-mode-vi h send-keys -X tree-collapse
bind-key -T choice-mode-vi l send-keys -X tree-expand
bind-key -T choice-mode-vi H send-keys -X tree-collapse-all
bind-key -T choice-mode-vi L send-keys -X tree-expand-all
bind-key -T copy-mode-emacs MouseDragEnd1Pane send-keys -X copy-pipe "reattach-to-user-namespace pbcopy"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe "reattach-to-user-namespace pbcopy"
# bind-key -T vi-copy v begin-selection
# bind-key -T vi-copy C-v rectangle-toggle
# bind-key -T vi-copy y copy-selection
# bind-key -T vi-choice h tree-collapse
# bind-key -T vi-choice l tree-expand
# bind-key -T vi-choice H tree-collapse-all
# bind-key -T vi-choice L tree-expand-all
# bind-key -T emacs-copy MouseDragEnd1Pane copy-pipe "reattach-to-user-namespace pbcopy"
# bind-key -T vi-copy MouseDragEnd1Pane copy-pipe "reattach-to-user-namespace pbcopy"

# resize panes
bind -n S-Left resize-pane -L 2
bind -n S-Right resize-pane -R 2
bind -n S-Down resize-pane -D 1
bind -n S-Up resize-pane -U 1

set-option -g allow-rename off 


## Status bar design
# status line
set -g status-justify centre
set -g status-bg default
set -g status-fg cyan
set -g status-interval 1

# messaging
# set -g message-fg black
# set -g message-bg yellow
# set -g message-command-fg blue
# set -g message-command-bg black

#window mode
# setw -g mode-bg cyan
# setw -g mode-fg white

# The modes
set -g clock-mode-colour colour45
set -g clock-mode-style 12
# setw -g mode-attr none
# setw -g mode-fg colour16
# setw -g mode-bg colour184

# The panes
# set -g pane-border-bg colour245
# set -g pane-border-fg colour245
# set -g pane-active-border-bg colour45
# set -g pane-active-border-fg colour45

# The statusbar
set -g status-position bottom
set -g status-bg colour235
set -g status-fg colour254
# set -g status-attr none
set -g status-left '#[bold]#{?client_prefix,#[fg=colour220],#[fg=colour207]} #{pane_current_command}#[default] #S [#P] '
set -g status-right ' #(battery-prompt tmux) #[fg=colour034]%a %b %e #[fg=colour082,bold]%l:%M:%S #[none]%p '
set -g status-right-length 50
set -g status-left-length 50

# setw -g window-status-current-fg colour45
# setw -g window-status-current-bg colour196
# setw -g window-status-current-attr bold
setw -g window-status-current-format ' #I:#W '

# setw -g window-status-fg colour245
# setw -g window-status-bg colour240
# setw -g window-status-attr none
setw -g window-status-format ' #I:#W '

# setw -g window-status-bell-attr bold
# setw -g window-status-bell-fg colour255
# setw -g window-status-bell-bg colour15

# The messages
# set -g message-attr none
# set -g message-fg colour87
# set -g message-bg colour235

# -- display -------------------------------------------------------------------

set-window-option -g automatic-rename on
set-option -g allow-rename off
set -g base-index 1
set -g pane-base-index 1
set -g automatic-rename-format '#(basename #{pane_current_path})'
set -g renumber-windows on
set -g set-titles on
set -g set-titles-string '#{pane_current_path} #S:#I — #{pane_current_command}'

# activity
set -g monitor-activity on
set -g visual-activity on
