##
##  ~/.tmux.conf -- tmux(1) configuration
##  Copyright (c) 1995-2019 Ralf S. Engelschall <rse@engelschall.com>
##  Distributed under MIT <https://opensource.org/licenses/MIT> license.
##

#   switch prefix key to CTRL+a like screen(1)
unbind-key C-b
set-option -g prefix C-a
bind-key a send-prefix
bind-key C-a last-window

#   remove unnecessary key bindings
unbind-key n
unbind-key Space
unbind-key "'"
unbind-key '"'
unbind-key "#"
unbind-key "\$"
unbind-key "&"
unbind-key ","
unbind-key "."
unbind-key ";"
unbind-key "}"
unbind-key "{"
unbind-key "["
unbind-key "]"
unbind-key PPage
unbind-key M-1
unbind-key M-2
unbind-key M-3
unbind-key M-4
unbind-key M-5
unbind-key M-n
unbind-key M-o
unbind-key M-p
unbind-key C-Up
unbind-key C-Down
unbind-key C-Left
unbind-key C-Right
unbind-key M-Up
unbind-key M-Down
unbind-key M-Left
unbind-key M-Right

#   global Alt+LEFT/RIGHT cycles through windows
#   global Alt+UP/DOWN cycles through panes
bind-key -n M-Right select-window -n
bind-key -n M-Left  select-window -p
bind-key -n M-Up    select-pane -t:.-
bind-key -n M-Down  select-pane -t:.+

#   configure special pane handling
unbind-key %
bind-key |     split-window -h -c "#{pane_current_path}"
bind-key -     split-window -v -c "#{pane_current_path}"
bind-key Left  select-pane -L
bind-key Right select-pane -R
bind-key Up    select-pane -U
bind-key Down  select-pane -D
bind-key z     resize-pane -Z
bind-key x     kill-pane
bind-key o     rotate-window
bind-key "#"   next-layout
bind-key s     set-window-option -g synchronize-panes
set-option -g mouse on
set-option -g -w pane-active-border-style fg=red
set-option -g -w pane-border-style        fg=default

#   configure special window handling
bind-key c      new-window -c "#{pane_current_path}"
bind-key Tab    choose-tree -Z
bind-key k      confirm-before "kill-window"
bind-key -r "<" swap-window -t -1
bind-key -r ">" swap-window -t +1
bind-key Space  next-window
bind-key d      detach-client

#   configure copy buffer
set-option -g -w mode-keys vi
bind-key v copy-mode
bind-key -T copy-mode-vi v      send-keys -X begin-selection
bind-key -T copy-mode-vi V      send-keys -X start-of-line \; send-keys -X begin-selection \; send-keys -X end-of-line
bind-key -T copy-mode-vi C-v    send-keys -X begin-selection \; send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y      send-keys -X copy-selection-and-cancel
bind-key -T copy-mode-vi Enter  send-keys -X copy-selection-and-cancel
bind-key -T copy-mode-vi Space  send-keys -X clear-selection
bind-key -T copy-mode-vi Escape send-keys -X cancel
bind-key p paste-buffer
bind-key P choose-buffer -Z -O time

#   general options
set-option -g history-limit 10000
set-option -g display-panes-time 2000
set-option -g display-time 4000
set-option -g base-index 1
set-option -g bell-action any
set-option -g visual-activity on
set-option -g focus-events on
set-option -g -s escape-time 50
set-window-option -g monitor-activity on

#   status bar providing window and pane information
set-option -g status-keys                  emacs
set-option -g status-style                 fg=default,bg=default,reverse
set-option -g status-justify               right
set-option -g status-left                  " #(echo $LOGNAME)#{?session_attached, <#{session_name}>,} #[fg=red] #I [#{window_panes}] "
set-option -g status-left-length           20
set-option -g status-right                 ""
set-option -g status-right-length          60
set-option -g window-status-format         " #I #W "
set-option -g window-status-current-format "#[fg=red] #I #W "

