###############################################################################
#    tmux common profile
#      This tmux configuration profile is intended to correspond to Byobu's
#      traditional GNU Screen profile
#
#    Copyright (C) 2011 Dustin Kirkland
#
#    Authors: Dustin Kirkland <kirkland@ubuntu.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, version 3 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
###############################################################################

# Initialize environment, clean up
set-environment -g BYOBU_BACKEND tmux
new-window -d byobu-janitor
set -s escape-time 0

# Change to Screen's ctrl-a escape sequence
source /usr/share/doc/tmux/examples/screen-keys.conf

# Byobu's Keybindings
bind-key -n F1 new-window -k -t config byobu-config
bind-key -n F2 new-window
bind-key -n F3 previous-window
bind-key -n F4 next-window
bind-key -n F5 source /usr/share/byobu/profiles/tmuxrc
bind-key -n F6 detach
bind-key -n S-F6 run-shell 'exec touch $BYOBU_RUN_DIR/no-logout' \; detach
bind-key -n C-F6 kill-pane
bind-key -n F7 copy-mode
bind-key -n M-NPage copy-mode \; send-keys NPage
bind-key -n M-PPage copy-mode \; send-keys PPage
bind-key -n F8 command-prompt -p "(rename-window)" "rename-window %%"
bind-key -n F9 new-window -a byobu-config
bind-key -n C-F2 display-panes \; split-window -h
bind-key -n S-F2 display-panes \; split-window -v
bind-key -n S-F3 display-panes \; select-pane -t :.-
bind-key -n S-F4 display-panes \; select-pane -t :.+
bind-key -n C-F3 display-panes \; swap-pane -s :. -t :.- \; select-pane -t :.-
bind-key -n C-F4 display-panes \; swap-pane -s :. -t :.+ \; select-pane -t :.+
bind-key -n S-F5 next-layout
bind-key -n S-Up display-panes \; select-pane -U
bind-key -n S-Down display-panes \; select-pane -D
bind-key -n S-left display-panes \; select-pane -L
bind-key -n S-right display-panes \; select-pane -R
bind-key -n C-Up resize-pane -U
bind-key -n C-Down resize-pane -D
bind-key -n C-Left resize-pane -L
bind-key -n C-Right resize-pane -R
bind-key -n M-left previous-window
bind-key -n M-right next-window
bind-key -n M-Up choose-session \; send-keys Up \; send-keys Enter
bind-key -n M-Down choose-session \; send-keys Down \; send-keys Enter

set-option -g set-titles on
set-option -g set-titles-string '#(whoami)@#H - byobu (#S)'
set-option -g pane-active-border-bg magenta
set-option -g pane-active-border-fg magenta
set-option -g pane-border-fg white
set-option -g history-limit 10000
set-option -g display-panes-time 150
set-option -g display-panes-colour magenta
set-option -g display-panes-active-colour red
set-option -g clock-mode-colour magenta
set-option -g clock-mode-style 24
set-option -g mode-keys vi
set-option -g mode-bg magenta
set-option -g mode-fg white

set-window-option -g window-status-attr default
set-window-option -g window-status-bg black
set-window-option -g window-status-fg white
set-window-option -g window-status-current-attr default
set-window-option -g window-status-current-bg white
set-window-option -g window-status-current-fg black
set-window-option -g window-status-alert-bg black
set-window-option -g window-status-alert-fg white
set-window-option -g window-status-alert-attr bold
set-window-option -g automatic-rename on
set-window-option -g aggressive-resize on
set-window-option -g monitor-activity on
#set-window-option -g xterm-keys on

# Must set default-command to $SHELL, in order to not source ~/.profile
# BUG: Should *not* hardcode /bin/bash here
set -g default-terminal "screen-256color"
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
set -g default-command /bin/bash
set -g status-bg black
set -g status-fg white
set -g status-interval 1
set -g status-left-length 256
set -g status-right-length 256
set -g status-left '#(byobu-status tmux_left)['
set -g status-right ']#(byobu-status tmux_right)'
set -g message-bg magenta
set -g message-fg white

# Allow local overrides
source $BYOBU_CONFIG_DIR/.tmux.conf
