# basic {{{ 

# reload config file (change file location to your the tmux.conf you want to use)
bind r source-file ~/.tmux.conf
# prefix
unbind C-b
set-option -g prefix C-Space
bind-key C-Space send-prefix
# Enable mouse mode (tmux 2.1 and above)
set -g mouse on

set -s escape-time 0
unbind '"'
unbind %

bind-key , command-prompt "rename-session '%%'"
bind-key -n M-d detach
bind-key -n M-c copy-mode

bind v split-window -v

is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard'

#  }}} # 

#  panes {{{ # 

bind-key -n M-h if-shell "$is_vim" "send-keys M-h"  "select-pane -L"
bind-key -n M-j if-shell "$is_vim" "send-keys M-j"  "select-pane -D"
bind-key -n M-k if-shell "$is_vim" "send-keys M-k"  "select-pane -U"
bind-key -n M-l if-shell "$is_vim" "send-keys M-l"  "select-pane -R"
# bind-key -n M-\ if-shell "$is_vim" "send-keys M-\\" "select-pane -l"
bind-key -T copy-mode-vi M-h select-pane -L
bind-key -T copy-mode-vi M-j select-pane -D
bind-key -T copy-mode-vi M-k select-pane -U
bind-key -T copy-mode-vi M-l select-pane -R
# bind-key -T copy-mode-vi M-\ select-pane -l

bind-key -n M-Enter split-window -h
# bind-key -n M-v split-window -h

bind-key m select-pane -m
bind-key j join-pane \; select-layout main-vertical

bind-key -n M-q kill-pane

#  }}} panes # 

#  windows {{{ # 

bind-key -n M-w new-window
bind x kill-window
bind-key -n M-a command-prompt "rename-window '%%'"
# bind-key , command-prompt "rename-window '%%'"

bind-key -n M-p previous-window
bind-key -n M-n next-window
bind-key -n C-Left swap-window -t -1\; previous-window
bind-key -n C-Right swap-window -t +1\; next-window

#  }}} windows # 

#  status bar {{{ # 

#
# Powerline Double Cyan - Tmux Theme
# Created by Jim Myhrberg <contact@jimeh.me>.
#
# Inspired by vim-powerline: https://github.com/Lokaltog/powerline
#
# Requires terminal to be using a powerline compatible font, find one here:
# https://github.com/Lokaltog/powerline-fonts
#

# Status update interval
set -g status-interval 60

# Basic status bar colors
set -g status-style fg=colour240,bg=colour233

# Left side of status bar{{{
set -g status-left-style bg=colour233,fg=colour243
set -g status-left-length 40
# set -g status-left "#[fg=colour233,bg=colour39,bold] #S #[fg=colour39,bg=colour240,nobold]#[fg=colour233,bg=colour240] #(whoami) #[fg=colour240,bg=colour235]#[fg=colour240,bg=colour235] #I:#P #[fg=colour235,bg=colour233,nobold]"
# set -g status-left "#[fg=colour233,bg=colour39,bold] #S:#P #[fg=colour39,bg=colour233,nobold]"
set -g status-left "#[fg=colour233,bg=colour240] #S #[fg=colour240,bg=colour235] #P #[fg=colour235,bg=colour233]"
# }}}

# Right side of status bar{{{
set -g status-right-style bg=colour233,fg=colour243
set -g status-right-length 150
# set -g status-right "#[fg=colour235,bg=colour233]#[fg=colour240,bg=colour235] %H:%M #[fg=colour240,bg=colour235]#[fg=colour233,bg=colour240] %d-%b-%y #[fg=colour39,bg=colour240]#[fg=colour233,bg=colour39,bold] #H "
# set -g status-right "#[fg=colour235,bg=colour233]#[fg=colour240,bg=colour235] %H:%M #[fg=colour240,bg=colour235]#[fg=colour233,bg=colour240] %a-%m-%d #[fg=colour39,bg=colour240]"
# }}}

# Window status
set -g window-status-format "  #I:#W#F  "
set -g window-status-current-format "#[fg=colour233,bg=black]#[fg=colour81,nobold] #I:#W#F #[fg=colour233,bg=black,nobold]"

# Current window status
set -g window-status-current-style bg=colour39,fg=colour235

# Window with activity status
set -g window-status-activity-style bg=colour233,fg=colour245

# Window separator
set -g window-status-separator ""

# Window status alignment
set -g status-justify centre

# Pane border
set -g pane-border-style bg=default,fg=colour238

# Active pane border
set -g pane-active-border-style bg=default,fg=colour39

# Pane number indicator
set -g display-panes-colour colour233
set -g display-panes-active-colour colour245

# Clock mode
set -g clock-mode-colour colour39
set -g clock-mode-style 24

# Message
set -g message-style bg=colour39,fg=black

# Command message
set -g message-command-style bg=colour233,fg=black

# Mode
set -g mode-style bg=colour39,fg=colour232

#  }}} status bar # 

#  plugins {{{

set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# set -g @plugin 'jimeh/tmux-themepack'
# set -g @themepack 'powerline/double/blue'

set -g @plugin 'christoomey/vim-tmux-navigator'

run -b '~/.tmux/plugins/tpm/tpm'

#  }}} plugins #