#quick reload and edit config
bind-key r source-file ~/.config/serious-tmux/serious.tmux.conf \; display-message "Tmux config reloaded"
bind-key e split-window -h "nvim ~/.config/serious-tmux/serious.tmux.conf"

# split windows like vim
bind s split-window -v -c '#{pane_current_path}' 
bind v split-window -h -c '#{pane_current_path}' 

# move around panes with hjkl
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
unbind l
bind l select-pane -R

#activate mouse
set -g mouse on

# From https://github.com/tmux/tmux/issues/1320
# Emulate scrolling by sending up and down keys if these commands are running in the pane
tmux_commands_with_legacy_scroll="nano less more man git"

bind-key -T root WheelUpPane \
	if-shell -Ft= '#{?mouse_any_flag,1,#{pane_in_mode}}' \
		'send -Mt=' \
		'if-shell -t= "#{?alternate_on,true,false} || echo \"#{tmux_commands_with_legacy_scroll}\" | grep -q \"#{pane_current_command}\"" \
			"send -t= Up" "copy-mode -et="'

bind-key -T root WheelDownPane \
	if-shell -Ft = '#{?pane_in_mode,1,#{mouse_any_flag}}' \
		'send -Mt=' \
		'if-shell -t= "#{?alternate_on,true,false} || echo \"#{tmux_commands_with_legacy_scroll}\" | grep -q \"#{pane_current_command}\"" \
			"send -t= Down" "send -Mt="'



# vi-style controls for copy-mode
setw -g mode-keys vi
setw -g xterm-keys on

# Get 24 bit colors
set -ga terminal-overrides ",xterm-256color:Tc"
# set -ga terminal-overrides 'xterm*:smcup@:rmcup@'

# Recommended by nvim from ':checkhealth'
set-option -sg escape-time 0

# Nord Theme
# Powerline
run-shell "powerline-daemon -q"
# source "$/home/shawn/.config/powerline/themes/tmux///tmux/powerline.conf"
# set -g status-right ''

# set -g @plugin "arcticicestudio/nord-tmux"
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @continuum-save-interval '15'
set -g @continuum-restore 'off'
set -g @plugin 'tmux-plugins/tmux-continuum'
run -b "~/.config/serious-tmux/serious/plugins/tpm/tpm"

set -g status-right-length 240
set -g status-left-length 140

set -g status-right 'Continuum status: #{continuum_status}'
# set -g status-left 'Continuum status: #{continuum_status}'

set -g status-right "#{pane_current_path}                    "
set -ag status-right "#{prefix_highlight}"
set -ag status-right '#[fg=brightblack,bg=black,nobold,noitalics,nounderscore]#[fg=white,bg=brightblack] Continuum: #{@continuum-restore} #[fg=white,bg=brightblack,nobold,noitalics,nounderscore] '
run -b "~/.config/serious-tmux/serious/plugins/tpm/tpm"
run-shell "~/.config/serious-tmux/serious/plugins/nord-tmux/nord.tmux"
# set -ag status-left "#{prefix_highlight}"

# set -g pane-border-status on
set -g pane-border-style "bg=default,fg=default"
set -g pane-active-border-style "bg=default,fg=green"
# Pane naming
# toggle pane title visibility from https://github.com/tmux/tmux/issues/680
bind H run 'zsh -c "arr=( off top ) && tmux setw pane-border-status \${arr[\$(( \${arr[(I)#{pane-border-status}]} % 2 + 1 ))]}"'

# rename pane
bind P command-prompt -p "(rename-pane)" -I "#T" "select-pane -T '%%'"

# Choose Tree
unbind T
bind T choose-tree

# The following 10 lines are all from https://gitlab.com/protesilaos/dotfiles/blob/master/tmux/.tmux.conf
# copy mode
# Vim copy-paste behaviour using the clipboard
# bind -T copy-mode-vi v send-keys -X begin-selection
unbind -T copy-mode-vi v
# bind -T copy-mode-vi y send-keys -X copy-pipe "xclip -selection clipboard -i"
unbind -T copy-mode-vi y
# bind -T copy-mode-vi r send-keys -X rectangle-toggle
unbind -T copy-mode-vi r
# For vi copy mode bindings
# bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe "xclip -selection clipboard -i"
unbind -T copy-mode-vi MouseDragEnd1Pane
# For emacs copy mode bindings
# bind -T copy-mode MouseDragEnd1Pane send-keys -X copy-pipe "xclip -selection clipboard -i"
unbind -T copy-mode MouseDragEnd1Pane


# set -g status-utf9 on
# set -ag window-status-current-format "#[fg=black,bg=white,nobold,noitalics,nounderscore]"
# set -ag window-status-current-format "#[fg=black,bg=white]#P #{pane-border-status} #{pane-current-command}"
# set -ag window-status-current-format "#[fg=black,bg=white,nobold,noitalics,nounderscore]"
# set -ag window-status-current-format "#[fg=black,bg=white]#{pane_current_command}"
# set -ag window-status-current-format "#[fg=white,bg=black,nobold,noitalics,nounderscore]"
# set -ag window-status-current-format "#[fg=red,bg=black] #{pane_current_path}"
# set -ag window-status-current-format ' '

