set-environment -g PATH "/usr/local/bin:/bin:/usr/bin:/opt/homebrew/bin"
set -g default-terminal "tmux-256color"
set -sa terminal-features ",xterm-256color:RGB"

set -g history-limit 20000

# Remap prefix
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
bind-key -n C-b send-keys C-b
#bind-key -n C-b send-prefix

# Use F12 to toggle hotekys on/off for nested remote tmux sessions
bind -T root F12  \
  set prefix None \;\
  set key-table off \;\
  set status-style "fg=colour245,bg=colour238"\;\
  refresh-client -S

bind -T off F12 \
  set -u prefix \;\
  set -u key-table \;\
  set -u status-style \;\
  refresh-client -S

setw -g mode-keys vi
set-option -g status-keys vi

bind | split-window -h -c '#{pane_current_path}'
bind - split-window -v -c '#{pane_current_path}'

# Switch windows
bind-key -n M-Left select-window -t -1
bind-key -n M-Right select-window -t +1

unbind '"'
unbind '%'
#bind-key -n M-left select-pane -L
#bind-key -n M-right select-pane -R
#bind-key -n M-up select-pane -U
#bind-key -n M-down select-pane -D
bind-key -n C-x resize-pane -Z
bind-key C-x send-keys C-x

bind k clear-history\; display "History cleared"

bind-key a set-window-option synchronize-panes

bind r source-file ~/.tmux.conf\; display "Conf reloaded!"

set -g mouse on
set-option -g focus-events on

#bind-key -Tcopy-mode-vi 'v' send -X begin-selection
#bind-key -Tcopy-mode-vi 'y' send -X copy-selection
#bind -Tcopy-mode-vi y send -X copy-pipe "xclip -i -sel p -f | xclip -i -sel c" \; display-message "copied to system clipboard"

# Smart pane switching with awareness of vim splits
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim='echo "#{pane_current_command}" | grep -iqE "(^|\/)g?(view|n?vim?x?)(diff)?$"'
bind -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
bind -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
bind -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
bind -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"

# Nano
bind-key C-x send-keys C-x
bind-key C-o send-keys C-o

# Copying - Most of this is done in tmux-yank!
# move x clipboard into tmux paste buffer
#bind C-p run "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer"
# move tmux copy buffer into x clipboard
# Vi copypaste mode
set-window-option -g mode-keys vi
set-option -s set-clipboard on
set -g @yank_with_mouse off
set -g @yank_action 'copy-pipe'
bind-key -Tcopy-mode-vi 'C-right' send -X next-word
bind-key -Tcopy-mode-vi 'C-left' send -X previous-word

if '[ `uname` == Darwin ]' \
    'source-file ~/.tmux/.mac_config'

set-option -g set-titles on


# Escape timeout for nvim
set -sg escape-time 10


# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-open'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'jimeh/tmux-themepack'
set -g @themepack 'powerline/double/blue'

setenv -g TMUX_PLUGIN_MANAGER_PATH "$HOME/.tmux/plugins/"

if "test ! -d ~/.tmux/plugins/tpm" \
  "run 'git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm && \
      ~/.tmux/plugins/tpm/bin/install_plugins'"

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run -b '~/.tmux/plugins/tpm/tpm || true'
