unbind C-b
set-option -g update-environment "SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"

set -g prefix C-a
bind C-a send-prefix

set -g mouse off

set -g prefix `
bind-key ` send-prefix

set -sg escape-time 0

# Hide pane with Prefix-h
bind-key h break-pane -d -n _hidden_pane
bind-key H join-pane -s $.1

# Tick -> Ctrl-A, sets prefix to Ctrl-A
bind-key C-a set-option -g prefix C-a

# Ctrl-A -> Ctrl-b, sets prefix to Tick
bind-key C-b set-option -g prefix `

set-option -g history-limit 100000000
set-option -g status-position bottom

set-option -g bell-action other
set-option -g visual-bell on

set -g base-index 1
set -g pane-base-index 1
set-option -g base-index 1
set-window-option -g pane-base-index 1

set -g @thumbs-osc52 '1'

# tmux-256color instead of screen-256color enables italics
set -g default-terminal "tmux-256color"

# Tc enables true color
set -ag terminal-overrides ",*256col*:colors=256:Tc"
set -as terminal-features ',rxvt-unicode-256color:clipboard'
# set -g default-shell zsh

# force a reload of the config file
unbind r
bind r source-file ~/.tmux.conf \; display "Reloaded!"

bind -n C-b send-keys -R \; clear-history \; send-keys C-l

set -g status on
set-option -g status-interval 2
bind Escape confirm-before "kill-server"

# set-option -g automatic-rename on
# set-option -g automatic-rename-format '#{?#{m/r:^(/google/src)?/cloud/,#{pane_current_path}},#{s|^(/google/src)?/cloud/[^/]+/([^/]+).+$|\2|:pane_current_path},#{b:pane_current_path}}'

set-window-option -g xterm-keys on
set-option -g xterm-keys on
set -g status-keys vi

set-option -g allow-passthrough on
set -s set-clipboard on

# Use vim keybindings in copy mode
setw -g mode-keys vi

# Setup 'v' to begin selection as in Vim
bind-key -T copy-mode-vi 'v' send -X begin-selection

set -g @yank_action 'copy-pipe' # or 'copy-pipe-and-cancel' for the default
set -g @override_copy_command 'lemonade copy'

# transfer copied text to attached terminal with yank
bind-key -T copy-mode-vi C-c send -X copy-pipe-no-clear "lemonade copy"

# allowd pane-navigation while in copy-mode
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


setw -g monitor-activity on

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

bind -n M-s set-window-option synchronize-panes\; display-message "synchronize-panes is now #{?pane_synchronized,on,off}"

bind -n M-z resize-pane -Z

bind -n M-j resize-pane -D 5
bind -n M-k resize-pane -U 5
bind -n M-h resize-pane -L 5
bind -n M-l resize-pane -R 5

# smart pane switching with awareness of vim splits
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"

# Shift arrow to switch windows
bind -n S-Left  previous-window
bind -n S-Right next-window

# Ctrl-Shift arrow to swap windows
bind-key -n C-S-Left swap-window -t -1\; select-window -t -1
bind-key -n C-S-Right swap-window -t +1\; select-window -t +1

# swap window to left or right
bind-key -r < swap-window -t -1\; select-window -t -1
bind-key -r > swap-window -t +1\; select-window -t +1

# loop through current window's panes while zoomed
bind -r "'" select-pane -t .+1 \;  resize-pane -Z
bind -r ";" select-pane -t .-1 \;  resize-pane -Z

bind-key C-a set-option -g prefix C-a

# No delay for escape key press
set -sg escape-time 0

set -g status-right '#{prefix_highlight} | %a %Y-%m-%d %H:%M'

set -g @catppuccin_window_default_fill "number"
# set -g @catppuccin_window_default_text "#W"
set -g @catppuccin_window_default_text "#{pane_current_path}"

set -g @catppuccin_window_current_fill "number"
# set -g @catppuccin_window_current_text "#W"
set -g @catppuccin_window_current_text '#{?#{m/r:^(/google/src)?/cloud/,#{pane_current_path}},#{s|^(/google/src)?/cloud/[^/]+/([^/]+).+$|\2|:pane_current_path},#{b:pane_current_path}}'

set -g @catppuccin_pane_status_enabled "yes"
set -g @catppuccin_pane_border_status "top"
set -g @catppuccin_pane_left_separator ""
set -g @catppuccin_pane_right_separator ""
set -g @catppuccin_pane_middle_separator "█ "
set -g @catppuccin_pane_number_position "left"
set -g @catppuccin_pane_default_fill "number"

set -g @catppuccin_status_modules_right "host cpu weather date_time"
set -g @catppuccin_status_left_separator  ""
set -g @catppuccin_status_right_separator " "
set -g @catppuccin_status_right_separator_inverse "yes"
set -g @catppuccin_status_fill "all"
set -g @catppuccin_status_connect_separator "no"
set -g @catppuccin_window_status_icon_enable "yes"

set -g @catppuccin_icon_window_last "󰖰"
set -g @catppuccin_icon_window_current "󰖯"
set -g @catppuccin_icon_window_zoom "󰁌"
set -g @catppuccin_icon_window_mark "󰃀"
set -g @catppuccin_icon_window_silent "󰂛"
set -g @catppuccin_icon_window_activity "󰖲"
set -g @catppuccin_icon_window_bell "󰂞"

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'christoomey/vim-tmux-navigator'
set -g @plugin 'tmux-plugins/tmux-cpu'
set -g @plugin 'xamut/tmux-weather'
set -g @plugin 'tmux-plugins/tmux-battery'
set -g @plugin 'tmux-plugins/tmux-cowboy' # Kill process in pane w/ prefix+*
set -g @plugin 'catppuccin/tmux'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'

set -g @continuum-restore 'on'
set -g @resurrect-dir '$HOME/.tmux/resurrect'

set -g @catppuccin_flavour 'macchiato' # or frappe, macchiato, mocha

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