# Tmux plugins, requires tmux plugin manager
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'

# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'github_username/plugin_name#branch'
# set -g @plugin 'git@github.com:user/plugin'
# set -g @plugin 'git@bitbucket.com:user/plugin'


# Config that is very close to a i3 window manager's keybinding.
set -s escape-time 0
setw -g aggressive-resize on
set -sg repeat-time 1000

# First remove *all* keybindings
unbind-key -a

# List keys
bind-key ? list-keys

# Copy mode
bind-key [ copy-mode

# Paste buffer
bind-key ] paste-buffer

# Refresh client
bind-key r refresh-client \; display-message "Refresh already"

# Start with index 1
set -g base-index 1
setw -g pane-base-index 1

# Set new prefix
# Note : you can press super key by set M.
# (tested with tty only)
set -g prefix C-f
bind-key Space send-prefix

# Clock
setw -g clock-mode-style 24

# Config Reloads
bind R source-file ~/.tmux.conf \; display-message "Config reloaded"

# Mouse on/off
set -g mouse on

# Split window (g=horizontal, v=vertical — matches WM configs)
bind-key g split-window -h
bind-key v split-window -v

# Rotate Window
# bind-key -n M-o rotate-window

# Swap pane
# bind-key -r H swap-pane -L
bind-key -r J swap-pane -D
bind-key -r K swap-pane -U
# bind-key -r L swap-pane -R

# Move pane with Control (no prefix)
bind-key  h select-pane -L
bind-key  j select-pane -D
bind-key  k select-pane -U
bind-key  l select-pane -R

# Resize pane with Alt (prefix with repeat)
bind-key -r C-H resize-pane -L 5 \; display-message "Resize left"
bind-key -r C-J resize-pane -D 5 \; display-message "Resize down"
bind-key -r C-K resize-pane -U 5 \; display-message "Resize up"
bind-key -r C-L resize-pane -R 5 \; display-message "Resize right"

# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on

# Choose Window
bind-key w choose-window

# New Window with number
bind-key 1 select-window -t 1
bind-key 2 select-window -t 2
bind-key 3 select-window -t 3
bind-key 4 select-window -t 4
bind-key 5 select-window -t 5
bind-key 6 select-window -t 6
bind-key 7 select-window -t 7
bind-key 8 select-window -t 8
bind-key 9 select-window -t 9
bind-key 0 select-window -t 10

# Switch windows alt+number
bind-key -n M-1 new-window -t 1
bind-key -n M-2 new-window -t 2
bind-key -n M-3 new-window -t 3
bind-key -n M-4 new-window -t 4
bind-key -n M-5 new-window -t 5
bind-key -n M-6 new-window -t 6
bind-key -n M-7 new-window -t 7
bind-key -n M-8 new-window -t 8
bind-key -n M-9 new-window -t 9
bind-key -n M-0 new-window -t 10

# Change current pane to next window
bind-key ! join-pane -t :1
bind-key @ join-pane -t :2
bind-key '#' join-pane -t :3
bind-key '$' join-pane -t :4
bind-key '%' join-pane -t :5
bind-key '^' join-pane -t :6
bind-key '&' join-pane -t :7
bind-key '*' join-pane -t :8
bind-key '(' join-pane -t :9
bind-key ')' join-pane -t :10

# Kill Selected Pane
bind-key q kill-pane


# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
