# Tmux Basic Configure
set -g mouse on
set -g mode-keys vi

# 讓終端支援 Truecolor
set-option -ga terminal-overrides ',*:Tc'

# == TPM Configure ============================================================
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'github_username/plugin_name#branch'
# set -g @plugin 'git@github.com:user/plugin'
# set -g @plugin 'git@bitbucket.com:user/plugin'
# set -g @plugin 'MunifTanjim/tmux-mode-indicator'
set -g @plugin 'aacebedo/tmux-mode-indicator'
set -g @plugin 'tmux-plugins/tmux-cpu'
set -g @plugin 'robhurring/tmux-uptime'
set -g @plugin 'tassaron/tmux-df'
# set -g @plugin 'anghootys/tmux-ip-address'
set -g @plugin 'tmux-plugins/tmux-net-speed' # Warning! 這個套件副作用會處理多餘空隔(對策是全形空隔)，以及內部可能有做正規表示式處理造成tmux-ip-address不正常
set -g @plugin 'jaclu/tmux-menus'

# == Plugin Configure =========================================================
set -g @cpu_percentage_format "%3.1f%%" # printf format to use to display percentage
set -g @net_speed_format "#[fg=green]⇣%s #[fg=yellow]⇡%s"

set -g @menus_location_x '0'
set -g @menus_location_y 'S'

# ---- tmux-mode-indicator ----------------------------------------------------
# prompt to display when tmux prefix key is pressed
set -g @mode_indicator_prefix_prompt ' PREFIX '
# prompt to display when tmux is in copy mode
set -g @mode_indicator_copy_prompt "　COPY　"
# prompt to display when tmux has synchronized panes
set -g @mode_indicator_sync_prompt '　SYNC　'
# prompt to display when tmux is in normal mode
set -g @mode_indicator_empty_prompt '　TERM　'

# add an element at the start of the indicator in <mode> mode (replace it with prefix, copy, sync or empty)
set -g @mode_indicator_prefix_end_prompt ''
set -g @mode_indicator_copy_end_prompt ''
set -g @mode_indicator_sync_end_prompt ''
set -g @mode_indicator_empty_end_prompt ''

# style values for prefix prompt
set -g @mode_indicator_prefix_mode_style 'bg=green,fg=black,bold'
# style values for copy prompt
set -g @mode_indicator_copy_mode_style 'bg=violet,fg=black,bold'
# style values for sync prompt
set -g @mode_indicator_sync_mode_style 'bg=red,fg=black,bold'
# style values for empty prompt
set -g @mode_indicator_empty_mode_style 'bg=cyan,fg=black,bold'

# stàle the element at the start of the indicator in <mode> mode (replace it with prefix, copy, sync or empty)
set -g @mode_indicator_prefix_mode_end_style 'fg=green,bg=yellow'
set -g @mode_indicator_copy_mode_end_style 'fg=violet,bg=yellow'
set -g @mode_indicator_sync_mode_end_style 'fg=red,bg=yellow'
set -g @mode_indicator_empty_mode_end_style 'fg=cyan,bg=yellow'

# == StatusBar Configure ======================================================
# tmux show-options -g | grep status-left

set -g status-interval 1
set -g status-keys vi
# set -g status-justify centre
set -g status-left-length 100
set -g status-right-length 100
set -g status-bg default
set -g status-fg white
set -g status-style "bg=black,fg=white"
set -g status-left "#[range=user|menu]#{tmux_mode_indicator}#[norange]#[range=user|detach]#[fg=black,bg=yellow] ❐ #{session_name} #[norange]#[fg=yellow,bg=white]#[fg=black,bg=white]#[range=user|sv]  #[norange]#[range=user|sh]  #[norange]#[range=user|new] 󰖲 #(tmux list-windows -t #{session_name} | wc -l)  #[norange]#[fg=white,bg=default]　"
set -g status-right "#[fg=gray,bg=default]#[range=user|bmon] ⇄ #{net_speed} #[norange]#[bg=default,fg=cyan]#[range=user|htop]#[fg=black,bg=cyan]  #{cpu_percentage}   #{df_avail} #[fg=pink,bg=cyan]#[norange]#[range=user|sysinfo]#[fg=black,bg=pink] #{?window_bigger,[#{window_offset_x}#,#{window_offset_y}] ,}\"#{=21:pane_title}\" #[norange]#[fg=white,bg=pink]#[range=user|clock]#[bg=white,fg=black]  #{uptime}  %H:%M:%S #[norange]"

# == StatusBar window Configure ===============================================
set -wg window-status-format  "#[fg=blue,bg=default]#{?#{<:#{window_index},10}, #{window_index},#{window_index}}#[bg=default,fg=blue]#[bg=default,fg=black]#[bg=default,fg=gray] #W#{?window_flags,#{window_flags}, } 　#[fg=blue,bg=default]"
set -wg window-status-current-format "#[fg=blue,bg=default]#[bg=blue,fg=black]#{?#{<:#{window_index},10}, #{window_index},#{window_index}}#[bg=blue,fg=black]#[bg=blue,fg=white] #W#{?window_flags,#{window_flags}, }#[range=user|close] 󰖭 #[norange]#[fg=blue,bg=default]" # 状态栏当前窗口名称格式(#I：序号，#w：窗口名 称，#F：间隔符)
# set -wg window-status-current-style "fg=#d7fcaf,bg=#60875f" # 状态栏当前窗口名称的样式
set -wg window-status-separator " " # 状态栏窗口名称之间的间隔
bind -Troot MouseDown1Status if -F '#{==:#{mouse_status_range},window}' {
    select-window
} {
    if -F '#{==:#{mouse_status_range},new}' {
        new-window
    }
    if -F '#{==:#{mouse_status_range},close}' {
        kill-pane
        # confirm-before kill-pane
    }
    if -F '#{==:#{mouse_status_range},sv}' {
        split-pane
    }
    if -F '#{==:#{mouse_status_range},sh}' {
        split-pane -h
    }
    if -F '#{==:#{mouse_status_range},detach}' {
        detach
        # confirm-before detach
    }
    if -F '#{==:#{mouse_status_range},htop}' {
        new-window htop
    }
    if -F '#{==:#{mouse_status_range},bmon}' {
        new-window bmon
    }
    if -F '#{==:#{mouse_status_range},sysinfo}' {
        new-window "neofetch && read -n 1 -p 'Press any key to continue...'"
    }
    if -F '#{==:#{mouse_status_range},clock}' {
        clock-mode
    }
    if -F '#{==:#{mouse_status_range},menu}' {
        run-shell "~/.tmux/plugins/tmux-menus/items/main.sh main"
    }
}

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

