#
#	.tmux.conf	Apr 2021
#

set -g mouse off

# set the terminal title depending on the current window
set -g set-titles on

### Generell key bindings
# turn vi key on
setw -g mode-keys vi
set -g status-keys vi
set -g base-index 1

### Some pane settings
# allow pane resizing via keystrokes
# single char/line resizing is bound to C-Left/Right/Up/Down by default
bind -T prefix -r C-h resize-pane -L 10
bind -T prefix -r C-j resize-pane -D 5
bind -T prefix -r C-k resize-pane -U 5
bind -T prefix -r C-l resize-pane -R 10

# Switch between panes using alt + arrow
bind -T root M-Left select-pane -L
bind -T root M-Right select-pane -R
bind -T root M-Up select-pane -U
bind -T root M-Down select-pane -D

# Define ALT-Cursor Keys on Mac OS/X Terminal, or 
# better redefine the Keys within the Terminal App to:
# ALT-Left=\033[1;3D & ALT-Right=\033[1;3C which correspond to xterm-256color
set escape-time 50
#set -s user-keys[0] "\eb"
#set -s user-keys[1] "\ef"
#set -s user-keys[2] "\e[A"
#set -s user-keys[3] "\e[B"
#bind -T root User0 select-pane -L
#bind -T root User1 select-pane -R
#bind -T root User2 select-pane -U
#bind -T root User3 select-pane -D

# toggle pane synchronisation
bind -T prefix C-s set-window-option synchronize-panes

# set pane border color
set -g pane-border-style "fg=black"
set -g pane-active-border-style "bg=default fg=green"
set -g pane-border-format "#h:#{pane_current_path}"
# set -g pane-border-format "#{pane_index} #{pane_title}"
set -g pane-border-status off	# off or top/bottom

set-option -g main-pane-height 10	# height of main window in main-horizontal style


### scroll/copy mode settings
# search within scroll/copy mode
bind -T root PPage copy-mode -eu	# use PgUp to start scrolling mode; ends automatically at buffer end
bind -T prefix / copy-mode \; send-key ?
bind -T copy-mode-vi 'v' send -X begin-selection
bind -T copy-mode-vi 'r' send -X rectangle-toggle
if-shell "uname | grep -q Darwin" {
	bind -T copy-mode-vi 'y' send -X copy-pipe-and-cancel "pbcopy"
	bind -T copy-mode-vi Enter send -X copy-pipe-and-cancel "pbcopy"
} {
	bind -T copy-mode-vi 'y' send -X copy-pipe-and-cancel "xclip -in -selection clipboard"
	bind -T copy-mode-vi Enter send -X copy-pipe-and-cancel "xclip -in -selection clipboard"
}
bind -T prefix P   paste-buffer -r
bind -T prefix C-p command-prompt -p "(paste-buffer):" "paste-buffer -b %%"


### Miscellaneous
# Center the window list ? Better not !
set -g status-justify left

# enable activity alerts
setw -g monitor-activity on
set -g visual-activity off

### Status line
# add weather report to status line (tmux show-options -g)
set-option -g status-interval 60
set-option -g status-right-length 65
set-option -g status-right-style "bg=green,fg=black"
set-option -g status-right "#{?window_bigger,[#{window_offset_x}#,#{window_offset_y}] ,}\"#{=21:host}\" %d-%b-%y %H:%M"
#set-option -g status-right "#{?window_bigger,[#{window_offset_x}#,#{window_offset_y}] ,}\"#{=21:pane_title}\" %H:%M %d-%b-%y"
#set-option -ag status-right " #[bg=#8a8787]#{pane_current_path}#[bg=default]"
set-option -ag status-right "#[bg=colour22 fg=white]#(weather -s -n)#[bg=default fg=default]"

# a slightly darker green background for the activ window
%if "#{m:*3*,#{version},r}"
  set-option -g window-status-current-style "bg=colour28,fg=white"
%else
  set-option -g window-status-current-bg colour28
%endif
