# improve colors
set -g default-terminal 'screen-256color'

source-file ~/.tmux/statusline.conf

bind s split-window -v
bind v split-window -h

# act like vim
setw -g mode-keys vi
set -g status-keys vi
# bind-key -t vi-edit Up
# bind-key -t vi-eidt Down
# 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 :+

# Move between tmux and vim seamlessly
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-l) || tmux select-pane -R"
bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys 'C-\\') || tmux select-pane -l"

#act like GNU screen
unbind C-b
set -g prefix C-a
bind-key C-a send-prefix

bind Escape copy-mode
# Setup 'v' to begin selection as in Vim
bind-key -t vi-copy v begin-selection
bind-key -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"
# resize panes like vim
# feel free to change the "1" to however many lines you want to resize by, only
# one at a time can be slow
bind < resize-pane -L 1
bind > resize-pane -R 1
bind - resize-pane -D 1
bind + resize-pane -U 1

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

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

bind-key r source ~/.tmux.conf

# Fix hightlighting in less
set -ga terminal-overrides ',*:sitm@,ritm@'

# 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

setw -g mode-mouse on

# Map window numbers
# bind-key & select-window -t 1
# bind-key é select-window -t 2
# bind-key " select-window -t 3
# bind-key ' select-window -t 4
# bind-key ( select-window -t 5
# bind-key § select-window -t 6
# bind-key è select-window -t 7
# bind-key ! select-window -t 8
# bind-key ç select-window -t 9


# Local config
if-shell "[ -f ~/.tmux.conf.local ]" 'source ~/.tmux.conf.local'
# bind -t vi-copy 'v' begin-selection
# bind -t vi-copy 'y' copy-pipe "reattach-to-user-namespace pbcopy"
set-option -g default-command "reattach-to-user-namespace -l zsh"

# Plugin Manager
set -g @tpm_plugins "               \
  tmux-plugins/tpm                  \
  tmux-plugins/tmux-sensible        \
  tmux-plugins/tmux-resurrect       \
  tmux-plugins/tmux-open            \
  tmux-plugins/tmux-copycat         \
"
run-shell ~/.tmux/plugins/tpm/tpm
