# 256 color
{{- if eq .hosttype "desktop" "laptop" }}
set -g default-terminal "alacritty"
{{- else }}
set -g default-terminal "tmux-256color"
{{- end }}
#set -ga terminal-overrides ',xterm-256color:RGB'

# increase limit of "scrollback buffer"
set -g history-limit 1000000

# reduce dely
set -sg escape-time 1

# enable mouse
setw -g mouse

# for neovim (adviced when running the :checkhealth command)
set-option -g focus-events on


#################
#  keybindings
#################

# Prefix
set-option -g prefix C-t
bind-key t send-prefix

# Reload config
bind r source-file $XDG_CONFIG_HOME/tmux/tmux.conf \; display-message "Config Reloaded!!"

# Split pane
bind C-l split-window -h -c '#{pane_current_path}'
bind C-j split-window -v -c '#{pane_current_path}'

# Session control
bind C-c new-session
{{- if eq .chezmoi.hostname "arch" }}
bind C-t run "tmuxsh          >/dev/null"
bind C-y run "tmuxsh remote   >/dev/null"
bind C-u run "tmuxsh dev      >/dev/null"
bind 0   run "tmuxsh wiki     >/dev/null"
bind 1   run "tmuxsh blog     >/dev/null"
bind 3   run "tmuxsh tessoku  >/dev/null"
bind 8   run "tmuxsh music    >/dev/null"
bind 9   run "tmuxsh util     >/dev/null"
{{- end }}


# Show pane number (can move to the pane by hit a num while it's displayed)
bind-key C-g display-panes



#########################
#  vim-like keybindings
#########################

# select pane
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# resize pane
bind -r H resize-pane -L 1
bind -r J resize-pane -D 1
bind -r K resize-pane -U 1
bind -r L resize-pane -R 1

# Copy mode
setw -g mode-keys vi
bind-key Escape copy-mode
bind-key -T copy-mode-vi Escape send-keys -X cancel
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi V send-keys -X select-line
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xsel -i -p && xsel -o -p | xsel -i -b"
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xsel -i -p && xsel -o -p | xsel -i -b"
bind-key p run "xsel -o | tmux load-buffer - ; tmux paste-buffer"



###########################
#  Aesthetic
###########################

{{- if eq .hosttype "desktop" "laptop" }}
set -g pane-active-border-style fg=yellow
set -g message-command-style 'fg=#eeeeee bg=#333333 bold'
set -g message-style 'fg=#eeeeee bg=#333333 bold'
set -g status off
set -g status-position top
set -g status-bg '#333333'
set -g status-fg '#eeeeee'
set -g status-left ''
set -g status-right ''
set -g window-status-format ''
set -g window-status-current-format ''
{{- else }}
set -g pane-active-border-style fg=red
set -g message-command-style 'fg=black bg=red bold'
set -g message-style 'fg=black bg=red bold'
set -g status on
set -g status-position top
set -g status-bg red
set -g status-fg black
set -g status-left " #[bold]#I:#P #W"
set -g status-left-length 40
set -g status-right "#[bold][#(whoami)@#H]"
set -g status-right-length 20
set -g window-status-format ''
set -g window-status-current-format ''
{{- end }}




{{- if eq .hosttype "desktop" "laptop" }}
###############################################
# local and nested remote tmux sessions
#   - https://www.freecodecamp.org/news/tmux-in-practice-local-and-nested-remote-tmux-sessions-4f7ba5db8795/
#   - https://gist.github.com/samoshkin/05e65f7f1c9b55d3fc7690b59d678734

bind -T root M-q \
    set prefix None \;\
    set key-table off \;\
    set status on \;\
    set status-right '#[bold align=centre]*LOCKED*'

bind -T off M-q \
    set -u prefix \;\
    set -u key-table \;\
    set -u status off \;\
    set status-right ''



#######################
#     Plugins
#######################

## List of plugins
set-environment -g TMUX_PLUGIN_MANAGER_PATH "$XDG_CACHE_HOME/tmux/plugins"

# Tmux Plugin Manager
set -g @plugin 'tmux-plugins/tpm'

set -g @plugin 'wfxr/tmux-fzf-url'

set -g @plugin 'fcsonline/tmux-thumbs'
set -g @thumbs-contrast 4
set -g @thumbs-bg-color 'black'
set -g @thumbs-fg-color 'yellow'
set -g @thumbs-hint-fg-color 'red'
set -g @thumbs-hint-bg-color 'black'
set -g @thumbs-position 'right'
set -g @thumbs-command 'echo -n {} | xsel -ib'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run -b "$XDG_CACHE_HOME/tmux/plugins/tpm/tpm"
{{- end }}