set-option -g allow-rename on
set-option -g automatic-rename off
set-option -g base-index 1
set-option -g default-command "$SHELL"
set-option -g default-terminal "tmux-256color"
set-option -g history-limit 25000
set-option -g mode-keys vi
set-option -g prefix C-f
set-option -g renumber-windows yes
set-option -g set-titles on
set-option -g set-titles-string "#T"
set-option -g xterm-keys on

set-option -g status-interval 1
set-option -g status-left "#(tmux-status-left)"
set-option -g status-left-length 40
set-option -g status-right ""

set-option -g window-status-current-attr bold
set-option -g window-status-current-format "[#I#F#{?window_zoomed_flag, ,}#{=40:pane_title}]"
set-option -g window-status-format "#I#{?window_zoomed_flag, ,}#F#{?window_flags,, }#{?window_zoomed_flag, ,}#{=20:pane_title}"

set-option -g pane-active-border-fg colour247
set-option -g pane-border-fg colour235
set-option -g status-bg colour7
set-option -g status-fg colour16
set-option -g status-left-bg colour4
set-option -g status-left-fg colour15
set-option -g window-status-current-bg colour15
set-option -g window-status-current-fg colour16

set-option -g update-environment "DBUS_SESSION_BUS_ADDRESS DISPLAY KRB5CCNAME \
    SESSION_MANAGER SSH_AGENT_PID SSH_ASKPASS SSH_AUTH_SOCK SSH_CONNECTION \
    WINDOWID XAUTHORITY SSH_TTY"

bind-key    w   break-pane -d
bind-key    l   clear-history \; display "Pane history cleared."
bind-key    C-f if-shell "test #{window_panes} -eq 1" last-window last-pane
bind-key    N   new-session
bind-key    t   new-window
bind-key    z   resize-pane -Z
bind-key    C-r rotate-window -D
bind-key -n C-t run-shell "metamux new-shell-in-pane #{window_panes}"
bind-key    n   run-shell "metamux rotate-pane next"
bind-key    p   run-shell "metamux rotate-pane prev"
bind-key    q   run-shell "metamux pane-buster"
bind-key    S   run-shell "metamux join-hidden-pane -v"
bind-key    u   run-shell "metamux open-last-url-printed"
bind-key    |   run-shell "metamux join-hidden-pane -h"
bind-key    f   send-prefix
bind-key    r   source "$HOME/.tmux.conf" \; display "Configuration reloaded."

# When the current window is split, Ctrl+Tab and Ctrl+Shift+Tab should rotate
# between the split windows. If there is only one pane in the current window,
# Ctrl+Tab and Ctrl+Shift+Tab will cycle between windows as though they were
# tabs in modern desktop UIs.
bind-key -n C-Tab   if-shell "test #{window_panes} -eq 1" next-window     "select-pane -t :.+"
bind-key -n C-S-Tab if-shell "test #{window_panes} -eq 1" previous-window "select-pane -t :.-"

# Binding to mark and swap panes; if no pane is marked, the shortcut will mark
# the active pane, but if a pane is already marked, active pane will be swapped
# with the marked pane.
bind-key m if-shell 'test -z "$PANE_IS_MARKED"' \
                    "select-pane -m; set-env PANE_IS_MARKED 1" \
                    "swap-pane; select-pane -M; set-env -u PANE_IS_MARKED"
