#-·-·-·-·-·-·-·-·-·-·-·-·-·-·-·-·-·-·-
# File : ~/.tmux.conf
# Author : bozze <github(a)bozze.org> + ria4
# vim:set fen fdm=marker:
#-·-·-·-·-·-·-·-·-·-·-·-·-·-·-·-·-·-·-

# GENERAL OPTIONS -----------------------------------------{{{

#setw -g utf8 on
#set -g status-utf8 on
set -g default-terminal "xterm-256color"
set -g base-index 1
set -g display-time 1000
# prefix Mac / PC / generic
set-option -g prefix C-b
#set-option -gw xterm-keys on
#set-option -g prefix '²'
#---}}}

# UNBIND FEW DEFAULT KEYS -------------------------------{{{
unbind-key '"' # split horizontal
unbind-key % # split vertical
unbind-key ( # previous client
unbind-key ) # next client
unbind-key w # choose window
unbind-key , # rename
unbind-key l # window list

# select pane
unbind-key Up
unbind-key Down
unbind-key Left
unbind-key Right

# select layout
unbind-key M-1
unbind-key M-2
unbind-key M-3
unbind-key M-4
unbind-key M-5

# next/prev window, next pane
unbind-key M-n
unbind-key M-p
unbind-key M-o

# resize 1 cell
unbind-key C-Up
unbind-key C-Down
unbind-key C-Left
unbind-key C-Right

# resize 5 cell
unbind-key M-Up
unbind-key M-Down
unbind-key M-Left
unbind-key M-Right

# windows selection
unbind-key 0
unbind-key 1
unbind-key 2
unbind-key 3
unbind-key 4
unbind-key 5
unbind-key 6
unbind-key 7
unbind-key 8
unbind-key 9
#---}}}

# MAIN KEY BINDINGS -------------------------------------{{{
bind-key @ last-window
bind-key & send-prefix
bind-key r source-file ~/.tmux.conf \; display-message "TMUX config reloaded..."
bind-key v paste-buffer
#---}}}

# MOUSE -------------------------------------------------{{{
# (press alt in iTerm to break xterm mouse reporting)
#set-window-option -g mouse-select-window on
#set-window-option -g mouse-resize-pane on
#set-window-option -g mode-mouse on
#set -g mouse-select-pane on
#---}}}

# PANES -------------------------------------------------{{{
#
# Shift + arrow to move through panes
bind-key -n S-Left select-pane -L
bind-key -n S-Right select-pane -R
bind-key -n S-Up select-pane -U
bind-key -n S-Down select-pane -D

# Ctrl+Shift+arrow in repeat mode repeat to resize panes
bind-key -nr C-S-Left resize-pane -L 1
bind-key -nr C-S-Right resize-pane -R 1
bind-key -nr C-S-Up resize-pane -U 1
bind-key -nr C-S-Down resize-pane -D 1

# Horizontal & vertical split
bind-key - split-window -v -c '#{pane_current_path}'
bind-key + split-window -h -c '#{pane_current_path}'

#set-window-option -g pane-active-border-bg default
#set-window-option -g pane-active-border-fg colour9
#set -g pane-active-border-bg default
#set -g pane-active-border-fg colour9
set -g pane-active-border-style fg=colour9,bg=default

#---}}}

# WINDOWS -----------------------------------------------{{{
bind-key -n F1 select-window -t :1
bind-key -n F2 select-window -t :2
bind-key -n F3 select-window -t :3
bind-key -n F4 select-window -t :4
bind-key -n F5 select-window -t :5
bind-key -n F6 select-window -t :6
bind-key -n F7 select-window -t :7
bind-key -n F8 select-window -t :8
bind-key -n F9 select-window -t :9
bind-key -n F10 select-window -t :10
bind-key -n F11 select-window -t :11
bind-key -n F12 select-window -t :12

bind-key '"' choose-window
bind-key "'" command-prompt "select-window -t ':%%'"
# Not good ver bind-key a command-prompt -I '#W' "rename-window '%%'"
bind-key m setw monitor-activity
bind-key % show-messages

bind-key / command-prompt -p ">> man page:" "split-window -h -l82 'exec man %%'"
bind-key T split-window -h -l82 'exec man tmux'
bind-key s command-prompt -p ">> SSH to:" "new-window -n %1 'ssh %1'"
bind-key * command-prompt -p ">> MOTP pin:" "run-shell 'tmux set-buffer \"$(~/bin/motpx %1)\" \\; paste-buffer -d \\; display-message \"MOTP sent to window #I, pane #P\"'"
bind-key n split-window -h -p50 'tmux send-keys #W'
#---}}}

# STATUS BAR --------------------------------------------{{{
# left part
set -g status-left-length 30
set -g status-left '#[fg=colour7,bg=colour0] #h#[fg=colour12,nobold]:#S '
#set -g status-left '#[fg=colour12,bg=colour0] #h#[fg=colour162,nobold]:#S #[bg=colour10] '

# center part
#set -g status-bg colour10
#set -g status-fg colour8
set -g status-bg '#4e4e4e'
set -g status-fg '#ffffff'
set -g status-interval 20
set-window-option -g window-status-format '#I·#W#F'

# right part
set -g status-right '#[bg=#bbbbbb]#[fg=#000000]#(cut -d " " -f -3 /proc/loadavg) #[bg=#4e4e4e]#[fg=#ffffff]#(date +" %H:%M ")'
#set -g status-right '#[default]#[bg=colour0] #[fg=colour2]%Y-%m-%d #[fg=colour10]~ #[fg=colour9,bg=colour0]%H:%M #[default]'

# current window
set-window-option -g window-status-current-style bg=colour14,fg=colour0,bold
set-window-option -g window-status-current-format ' #I·#W '

# alter window (bell / activity / content)
#set-window-option -g window-status-alert-style bg=colour10,fg=colour154,attr=bold
#---}}}

# VARIOUS OPTIONS ---------------------------------------{{{
# clock
set-window-option -g clock-mode-colour magenta
set-window-option -g clock-mode-style 24

# messages
set-window-option -g message-style bg=colour9,fg=colour8
set -g message-style bg=colour9,fg=colour8
#---}}}
