# Seth Woodworth's tmux configuration (http://sethish.com)
set-option -g default-shell /bin/zsh

# Terminals report to running programs what kind of terminal
# they are. screen-256color makes this just work on linux.
#set -g default-terminal "screen-256color"

# Each shell in every tmux pane keeps a history of
# scrollback lines. I might as well keep a lot of it,
# what am I going to do, run out of ram?
set -g history-limit 1000000

# set window size to the smallest user's screen
# that is viewing the window
# Useful when you have connect to remote terminals
setw -g aggressive-resize on

# put the tmux bar on top
set-option -g status-position top

# when in copy-mode, or selection windows in tmux
# use the h j k l vimlike movement keys
setw -g mode-keys vi

set -s escape-time 0

# Keybindings
# use C-a rather than C-b
unbind C-b
set -g prefix C-a
# use C-a C-a as flip windows as in screen
bind-key C-a last-window
# gnu-screen's next (space)
unbind " "
bind " " next-window
# gnu screen's prev (bspace)
unbind BSpace
bind BSpace previous-window
# rename window
unbind A
bind A command-prompt "rename-window %%"
# reload tmux conf
bind r source-file ~/.tmux.conf

# make - and | split the window horizontally and vertically
unbind %
bind | split-window -h
bind - split-window -v
# make = and l do down and right minimum splits
bind = split-window -v -l 5
unbind l
bind l splitw -h -l 80
# create 80c vertical window on the left side
bind h split-window -h -l 80 -b

# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-h if-shell "$is_vim" "send-keys C-h"  "select-pane -L"
bind-key -n C-j if-shell "$is_vim" "send-keys C-j"  "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k"  "select-pane -U"
bind-key -n C-l if-shell "$is_vim" "send-keys C-l"  "select-pane -R"
bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
bind-key -T copy-mode-vi C-h select-pane -L
bind-key -T copy-mode-vi C-j select-pane -D
bind-key -T copy-mode-vi C-k select-pane -U
bind-key -T copy-mode-vi C-l select-pane -R
bind-key -T copy-mode-vi C-\ select-pane -l

set -s escape-time 0

run-shell "powerline-daemon -q"
source "${HOME}/.local/venvs/powerline-status/lib/python3.7/site-packages/powerline/bindings/tmux/powerline.conf"

# Enable truecolor?
# set-option -ga terminal-overrides ",xterm-256color:Tc"
set -g default-terminal 'screen-256color'
set -ga terminal-overrides ',screen-256color:Tc'

source-file ~/.config/tmux/tmuxline.conf