# vim: ft=tmux

# Use `Ctrl-A` as the tmux command prefix instead of `Ctrl-B`.
unbind-key C-b
set-option -g prefix C-a

# Report the same $TERM value as we use for our terminal emulator (yes, go and
# set this) This influences, among other things, certain vim settings related to
# colours, rendering speed and mouse support.
set-option -g default-terminal "xterm-256color"

# Start windows and panes from `1`, not `0`.
set-option -g base-index 1
set-option -g pane-base-index 1

# History scrollback.
set-option -g history-limit 9999999

# Resize the window to the size of the smallest session for which it is the
# current window, rather than the smallest session to which it is attached.
set-window-option -g aggressive-resize on

# Act like vim.
set-option -g status-keys vi
set-window-option -g mode-keys vi # vi keys in copy mode (prefix+[)


#######################
# General Key Bindings
#######################

# Use prefix+r to reload the config file.
bind-key C-r source-file ~/.tmux.conf \; display-message "tmux.conf reloaded"

# Detach client like screen, <C-a> <C-d>.
bind-key C-d detach-client


###################################
# Window/Pane/Session Manipulation
###################################

# Window Movement.
bind-key -r C-h previous-window
bind-key -r C-l next-window
bind-key C-a last-window
bind-key -n M-1 select-window -t 1
bind-key -n M-2 select-window -t 2
bind-key -n M-3 select-window -t 3
bind-key -n M-4 select-window -t 4
bind-key -n M-5 select-window -t 5
bind-key -n M-6 select-window -t 6
bind-key -n M-7 select-window -t 7
bind-key -n M-8 select-window -t 8
bind-key -n M-9 select-window -t 9
bind-key -n M-0 select-window -t 10

# Window Creation/Destruction.
bind-key C-c new-window
# Remember prefix+, for renaming windows.

# Pane Movement.
bind-key h select-pane -L
bind-key j select-pane -D
bind-key k select-pane -U
bind-key l select-pane -R

# Pane Creation/Destruction.
unbind-key % # Remove default binding for horizontal split since we’re replacing it.
bind-key \ split-window -h
bind-key - split-window -v
bind-key C-x kill-pane

# Pane Sychronisation.
bind-key s set -w synchronize-panes

# Session Switching/Destruction.
bind-key C-s choose-session
bind-key X kill-session
# Remember prefix+$ for renaming sessions.

# Version-specific configuration.
if-shell '[[ $(version-compare $(tmux -V | sed "s/[tmux ]//g") 2.1) -lt 0 ]]' 'source-file ~/dotfiles/tmux/tmux1.conf'
if-shell '[[ $(version-compare $(tmux -V | sed "s/[tmux ]//g") 2.1) -ge 0 ]]' 'source-file ~/dotfiles/tmux/tmux2.conf'

# Colours and status line.
source-file ~/dotfiles/tmux/tmuxcolours.conf
