# $Id: $

unbind C-b # prefix
set -g prefix C-g

unbind l # last-window
bind-key C-g last-window
bind-key g send-keys C-g

unbind , # rename-window
bind-key A command-prompt "rename-window '%%'"

unbind '"' # split-window
bind-key '"' choose-window

bind-key escape copy-mode

bind-key S split-window

unbind % # split-window -h
bind-key V split-window -h

unbind Space # next-layout
bind-key Space next-window
bind-key C-Space next-layout

bind-key C-l refresh-client

bind-key h select-pane -L
bind-key j select-pane -D
bind-key k select-pane -U
bind-key l select-pane -R
bind-key tab select-pane -D

# Reload key
bind r source-file ~/.tmux.conf

# set -g default-terminal "screen-256color"
# set -g default-terminal "xterm"
set -g history-limit 1000

set -g status-keys vi
setw -g mode-keys vi
#set -g status-utf8 on
#setw -g utf8 on

set -g status-bg black
# set -g status-fg white
set -g status-fg green
set -g status-interval 60
# set -g status-left-length 14
# set -g status-left '#[fg=green](#S) #(whoami)@#H#[default]'
# set -g status-right '#[fg=yellow]#(cut -d " " -f 1-3 /proc/loadavg)#[default] #[fg=blue]%H:%M#[default]'

# THEME
# set -g status-left '#[fg=green]#(whoami)@#H#[default]'
# set -g status-justify centre
# # set -g status-bg blue
# set -g status-right 'load #(cut -d " " -f 1 /proc/loadavg) | mem #(backtick-freemem) | swap #(backtick-freeswap) %H:%M' #'#(sysctl vm.loadavg)'
# setw -g window-status-current-attr bright
# setw -g window-status-current-fg white
# setw -g window-status-current-bg blue
# # setw -g window-status-fg green
# setw -g window-status-format '#I:#W' # '#I:#W#F'
# setw -g window-status-current-format '#I:#W' # '#I:#W#F'

# select with mouse when copying
# setw -g mode-mouse on

# select pane with mouse
# set -g mouse-select-pane on

# use xterm-style function key sequences
# setw -g xterm-keys on

# set-option -g pane-border-fg white
# set-option -g pane-border-bg white
# set-option -g pane-active-border-fg green
# set-option -g pane-active-border-bg green

# new-window -n "pw" "vi /etc/passwd"

# set-option -g set-titles on
# # set-option -g set-titles-string '#S:#I.#P #W'
# set-option -g set-titles-string '#(whoami)@#H: #W | load #(cut -d " " -f 1 /proc/loadavg) | mem #(backtick-freemem) | swap #(backtick-freeswap) | inbox #(backtick-from)'
# # set-window-option -g automatic-rename on
# set-window-option -g aggressive-resize on



# set-option -g prefix C-a,C-b
# bind-key C-a send-keys C-a
# bind-key C-b send-keys C-b
# bind-key C-d detach-client
# set-option -g history-limit 1500
# set-option -g status-bg blue
# set-option -g status-fg white
#set set-remain-on-exit on
#bind-key -n c kill-pane
#bind-key -n r respawn-window

# original digraph by kirk
# bind-key v command-prompt -p "enter digraph:" "set-buffer \"%%\"; save-buffer /tmp/tmux-input; delete-buffer; if-shell '/home/makipri/bin/digraph -v < /tmp/tmux-input > /tmp/tmux-output' 'load-buffer /tmp/tmux-output; paste-buffer -d; run-shell \"/bin/rm /tmp/tmux-output /tmp/tmux-input\"'"

# customized
# bind-key v command-prompt -p "enter digraph:" "run-shell \"/bin/cat <<EOT\\n%%\\\nEOT >/tmp/mine\"; set-buffer %%; save-buffer /tmp/tmux-input; delete-buffer; if-shell '/home/makipri/bin/digraph -v < /tmp/tmux-input > /tmp/tmux-output' 'load-buffer /tmp/tmux-output; paste-buffer -d; run-shell \"/bin/rm /tmp/tmux-output /tmp/tmux-input\"'"

# customized v2
bind-key v command-prompt -p "enter digraph:" "if-shell \"~/bin/digraph -t -v \\\\\\%%\" 'pasteb -d'"

# testing
# bind-key v new-window "/home/makipri/bin/digraph >/tmp/tmux-output" \; new-window

# bind C-a command-prompt -p compose "if-shell \"~/compose.zsh \\\\\\%%\" 'pasteb -d' 'display \"not found\"'"
#bind C-a command-prompt -p compose "if-shell \"~/compose.zsh \\\\\\%%\" 'pasteb -d'"

# bind C-a command-prompt -p compose "if-shell \"~/compose.zsh ?o\" 'pasteb -d' 'display \"not found\"'"

set -s escape-time 100

# minimize and maximize pane
unbind +
bind + new-window -d -n tmux-zoom 'clear && echo TMUX ZOOM && read' \; swap-pane -s tmux-zoom.0 \; select-window -t tmux-zoom 
unbind -
bind - last-window \; swap-pane -s tmux-zoom.0 \; kill-window -t tmux-zoom

bind-key _ resize-pane -D 99

