# reload tmux
bind r source-file ~/.tmux.conf \; display "TMUX Config Reloaded"

# https://github.com/tmux/tmux/issues/543
# brew install reattach-to-user-namespace
# set -g default-shell $SHELL
# set -g default-command "reattach-to-user-namespace -l ${SHELL}"

# Start window number with 1
set-option -g base-index 1
# update numbering when 1 windows is closed
set-option -g renumber-windows on
set-window-option -g pane-base-index 1
set -g default-terminal "screen-256color"

# move to top the  navigation
set-option -g status-position top

set -g status-keys vi
set -g history-limit 50000

setw -g mode-keys vi
set -g mouse on
setw -g monitor-activity on

# Focus events
set-option -g focus-events on
set-option -sg escape-time 10 #https://github.com/neovim/neovim/wiki/Building-Neovim#optimized-builds

# Cycle panes with C-b C-b
unbind ^B
bind ^B select-pane -t :.+
unbind ^k

# split shortcut
bind v split-window -h -c "#{pane_current_path}"
bind s split-window -v -c "#{pane_current_path}"

# aggressive resize
set-window-option -g aggressive-resize on

# Resize pane shortcuts
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

# select pane
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-h if-shell "$is_vim" "send-keys C-h"  "select-pane -L"
bind-key -n C-j if-shell "$is_vim" "send-keys C-j"  "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k"  "select-pane -U"
bind-key -n C-l if-shell "$is_vim" "send-keys C-l"  "select-pane -R"
bind-key -n 'C-\' if-shell "$is_vim" "send-keys 'C-\\'" "select-pane -l"
bind-key -T copy-mode-vi C-h select-pane -L
bind-key -T copy-mode-vi C-j select-pane -D
bind-key -T copy-mode-vi C-k select-pane -U
bind-key -T copy-mode-vi C-l select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l

# Copy keys
bind P paste-buffer
bind-key -T copy-mode-vi 'v' send-keys -X begin-selection
bind-key -T copy-mode-vi 'r' send-keys -X rectangle-toggle
bind-key -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel 'reattach-to-user-namespace pbcopy'
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel 'reattach-to-user-namespace pbcopy'
bind -r k clear-history

# THEME
# This tmux statusbar config was created by tmuxline.vim
# Dec 2022
set -g message-style bg="colour31"
set -g message-style fg="colour231"
set -g message-command bg="colour31"
set -g message-command fg="colour231"
set -g pane-active-border-style fg="colour254"
set -g pane-border-style fg="colour240"

set -g status "on"
set -g status-style "none"
set -g status-bg "colour234"
set -g status-justify "left"
set -g status-left-style "none"
set -g status-left-length "100"
set -g status-right-style "none"
set -g status-right-length "100"

setw -g window-status-style fg="colour250"
setw -g window-status-style "none"
setw -g window-status-activity-style bg="colour234"
setw -g window-status-activity-style "none"
setw -g window-status-activity-style fg="colour250"

setw -g window-status-separator ""
setw -g window-status-style bg="colour234"
set -g status-left "#[fg=colour16,bg=colour254,bold] #S #[fg=colour254,bg=colour234,nobold,nounderscore,noitalics]"
set -g status-right "#[fg=colour236,bg=colour234,nobold,nounderscore,noitalics]#[fg=colour247,bg=colour236] %Y-%m-%d  %H:%M #[fg=colour252,bg=colour236,nobold,nounderscore,noitalics]#[fg=colour235,bg=colour252] #h "
setw -g window-status-format "#[fg=colour244,bg=colour234] #I #[fg=colour250,bg=colour234] #W "
setw -g window-status-current-format "#[fg=colour234,bg=colour31,nobold,nounderscore,noitalics]#[fg=colour117,bg=colour31] #I #[fg=colour231,bg=colour31,bold] #W #[fg=colour31,bg=colour234,nobold,nounderscore,noitalics]"