# Configure Tmux
set -g status-position top
set -g status-style "bg=#{@thm_bg}"
set -g status-justify "absolute-centre"
set -g prefix ^A
set -g base-index 1              # start indexing windows at 1 instead of 0
set -g detach-on-destroy off     # don't exit from tmux when closing a session
set -g escape-time 0             # zero-out escape time delay
set -g history-limit 1000000     # increase history size (from 2,000)
set -g renumber-windows on       # renumber all windows when any window is closed
set -g set-clipboard on          # use system clipboard
setw -g mode-keys vi
setw -g mouse on
if-shell 'echo $TERM | grep -q "xterm-kitty"' \
    'set -g default-terminal "kitty"; set -g terminal-overrides "xterm-kitty:Tc"' 
if-shell 'grep -qi microsoft /proc/version' \
    'set -g default-terminal "screen-256color"; set-option -sa terminal-overrides ",xterm-256color:RGB"'

set -g @plugin 'catppuccin/tmux'
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @plugin 'tmux-plugins/tmux-online-status'
set -g @plugin 'tmux-plugins/tmux-battery'
#set -g @plugin 'sainnhe/tmux-fzf'
#set -g @plugin 'wfxr/tmux-fzf-url'
#set -g @plugin 'fcsonline/tmux-thumbs'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'omerxx/tmux-sessionx'
#set -g @plugin 'omerxx/tmux-floax'

# Configure sessionx
set -g @sessionx-bind 'o'
#set -g @sessionx-bind-zo-new-window 'ctrl-y'
#set -g @sessionx-auto-accept 'off'
#set -g @sessionx-custom-paths '/Users/omerxx/dotfiles'
#set -g @sessionx-bind 'o'
#set -g @sessionx-x-path '~/dotfiles'
set -g @sessionx-window-height '85%'
set -g @sessionx-window-width '75%'
set -g @sessionx-zoxide-mode 'on'
#set -g @sessionx-custom-paths-subdirectories 'false'
set -g @sessionx-filter-current 'false'

# Configure Continuum
set -g @continuum-restore 'on'
#set -g @continuum-boot 'on' # Break the ressurect in my setup by saving at boot

# Configure Resurrect
set -g @resurrect-strategy-nvim 'session'
set -g @resurrect-capture-pane-contents 'on'
set -g @resurrect-processes 'ssh btop nvim lazygit yazi aichat spotify_player'

# Yazi image preview
set -g allow-passthrough on
set -ga update-environment TERM
set -ga update-environment TERM_PROGRAM

# Configure Catppuccin
set -g @catppuccin_flavor "macchiato"
set -g @catppuccin_status_background "none"
set -g @catppuccin_window_status_style "none"
set -g @catppuccin_pane_status_enabled "off"
set -g @catppuccin_pane_border_status "off"

## Configure Online
set -g @online_icon "ok"
set -g @offline_icon "nok"

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

## status left look and feel
set -g status-left-length 100
set -g status-left ""
set -ga status-left "#{?client_prefix,#{#[bg=#{@thm_red},fg=#{@thm_bg},bold]  #S },#{#[bg=#{@thm_bg},fg=#{@thm_green}]  #S }}"
set -ga status-left "#[bg=#{@thm_bg},fg=#{@thm_overlay_0},none]│"
set -ga status-left "#[bg=#{@thm_bg},fg=#{@thm_maroon}]  #{pane_current_command} "
set -ga status-left "#[bg=#{@thm_bg},fg=#{@thm_overlay_0},none]│"
set -ga status-left "#[bg=#{@thm_bg},fg=#{@thm_blue}]  #{=/-32/...:#{s|$USER|~|:#{b:pane_current_path}}} "
set -ga status-left "#[bg=#{@thm_bg},fg=#{@thm_overlay_0},none]#{?window_zoomed_flag,│,}"
set -ga status-left "#[bg=#{@thm_bg},fg=#{@thm_yellow}]#{?window_zoomed_flag,  zoom ,}"

## status right look and feel
set -g status-right-length 100
set -g status-right ""
set -ga status-right "#{?#{e|>=:10,#{battery_percentage}},#{#[bg=#{@thm_red},fg=#{@thm_bg}]},#{#[bg=#{@thm_bg},fg=#{@thm_pink}]}} #{battery_icon} #{battery_percentage} "
set -ga status-right "#[bg=#{@thm_bg},fg=#{@thm_overlay_0}, none]│"
set -ga status-right "#[bg=#{@thm_bg}]#{?#{==:#{online_status},ok},#[fg=#{@thm_mauve}] 󰖩 on ,#[fg=#{@thm_red},bold]#[reverse] 󰖪 off }"
set -ga status-right "#[bg=#{@thm_bg},fg=#{@thm_overlay_0}, none]│"
set -ga status-right "#[bg=#{@thm_bg},fg=#{@thm_blue}] 󰭦 %Y-%m-%d 󰅐 %H:%M "

# pane border look and feel
setw -g pane-border-status top
setw -g pane-border-format ""
setw -g pane-active-border-style "bg=#{@thm_bg},fg=#{@thm_overlay_0}"
setw -g pane-border-style "bg=#{@thm_bg},fg=#{@thm_surface_0}"
setw -g pane-border-lines single

# window look and feel
set -wg automatic-rename on
set -g automatic-rename-format "Window"

set -g window-status-format " #I#{?#{!=:#{window_name},Window},: #W,} "
set -g window-status-style "bg=#{@thm_bg},fg=#{@thm_rosewater}"
set -g window-status-last-style "bg=#{@thm_bg},fg=#{@thm_peach}"
set -g window-status-activity-style "bg=#{@thm_red},fg=#{@thm_bg}"
set -g window-status-bell-style "bg=#{@thm_red},fg=#{@thm_bg},bold"
set -gF window-status-separator "#[bg=#{@thm_bg},fg=#{@thm_overlay_0}]│"

set -g window-status-current-format " #I#{?#{!=:#{window_name},Window},: #W,} "
set -g window-status-current-style "bg=#{@thm_peach},fg=#{@thm_bg},bold"

run '/usr/share/tmux-plugin-manager/tpm'
run '~/.tmux/plugins/catppuccin/tmux/catppuccin.tmux'
