#
# Tureba's tmux.conf
#
#   To use it, either:
#       a) link ~/.tmux.conf to it; or
#       b) create a ~/.tmux.conf that sources it.
#
# who: Arthur Nascimento <tureba@gmail.com>
# where: github.com/tureba/myconfigfiles
#

# defaults
set -g default-shell /bin/zsh
set -g default-command zsh
# tmux sets screen/screen-256, but has no codes for italics
set -g default-terminal tmux-256color
# linux terminal doesn't need this, but xterm does
set -g terminal-overrides 'xterm*:smcup@:rmcup@,*256col*:colors=256,xterm*:XT'
# xterm-style function key sequences
setw -g xterm-keys on

# 1, 2 and 3 are closer together than 0, 1 and 2
set -g base-index 1
set -g pane-base-index 1

# easier to type than C-b
set -g prefix C-a
set -g prefix2 C-b
unbind C-b
bind C-a send-prefix

# for repeatable keys
set -g repeat-time 170

# status bar
set -g status-style fg=green,bg=colour234
set -g status-right-style bg=colour236
set -g status-right "#[bold,fg=blue][#[fg=default]#T#[fg=blue]]#[nobold,fg=default] | #[fg=yellow]%F %R"
set -g status-right-length 120
set -g status-left-style bg=colour236,bright
set -g status-left "#[fg=blue][#[fg=default]#h#[fg=cyan]:#[fg=default]#S#[fg=blue]]"
set -g status-left-length 30
setw -g window-status-style fg=green
setw -g window-status-format " #I#[nobold]:#W "
setw -g window-status-current-style fg=green,bright
setw -g window-status-current-format "#[fg=red][#[fg=default]#I:#W#[fg=red]]"
setw -g window-status-separator "|"
setw -g window-status-activity-style blink
setw -g window-status-bell-style blink
setw -g window-status-last-style bright

# enable wm window titles
set -g set-titles on

# auto window rename
setw -g automatic-rename on
# auto window resize
setw -g aggressive-resize on

# mouse settings
set -g mouse on

# var|bind \ cmd  |   vim   |   less    | copy |  zsh
# pane_in_mode    |    0    |     0     |   1  |   0
# mouse_any_flag  |    1    |     0     |   0  |   0
# alternate_on    |    1    |     1     |   0  |   0
# WheelUpPane     | send -M | send Up   |   *  | send Up (** or copy-mode -e)
# WheelDownPane   | send -M | send Down |   *  | send Down
# * panes in copy mode have scroll handled by different bindings

# ** cycle over shell history
#bind -T root WheelUpPane if -Ft= '#{mouse_any_flag}' 'send -Mt=' 'send -t= Up'

# ** enter copy mode
bind -T root WheelUpPane if -Ft= '#{mouse_any_flag}' 'send -Mt=' 'if -Ft= "#{alternate_on}" "send -t= Up" "copy-mode -et="'

bind -T root WheelDownPane if -Ft= '#{mouse_any_flag}' 'send -Mt=' 'send -t= Down'

# sensible v/h splits
unbind %
unbind '"'
bind | split-window -h
bind - split-window -v

# hjkl pane traversal
bind -r h select-pane -L
bind -r j select-pane -D
bind -r k select-pane -U
bind -r l select-pane -R

# window navigation
unbind p
bind -r [ previous-window
unbind n
bind -r ] next-window

# Vi copypaste mode
setw -g mode-keys vi
bind C-c copy-mode
bind p paste-buffer
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-selection
bind -T copy-mode-vi V send-keys -X rectangle-toggle

# toggle window activity monitoring
bind m setw monitor-activity

# reload the configuration
bind r source-file ~/.tmux.conf

# toggle synchronize-panes
bind S setw synchronize-panes

# create a new window with exactly this command
bind C command-prompt "new-window 'exec %%'"

# (toggle) mark this pane for easier joins and swaps
bind . select-pane -m
