# Plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'tmux-plugins/tmux-open'
set -g @plugin 'tmux-plugins/tmux-copycat'
set -g @plugin 'tmux-plugins/tmux-battery'

# Battery plugin settings
set -g @batt_charged_icon ""
set -g @batt_charging_icon ""
set -g @batt_attached_icon "ﮣ"
set -g @batt_full_charge_icon ""
set -g @batt_medium_charge_icon ""
set -g @batt_low_charge_icon ""

# Main settings
set -g base-index 1
set -g default-terminal screen-256color
set -g mouse on
set -g pane-active-border-style 'fg=green bg=default'
set -g pane-border-style 'fg=brightblack bg=default'
set -g prefix M-\;
set -g set-titles on
set -g set-titles-string "#W"
# set -g status-left-length 40
setw -g clock-mode-style 12
setw -g mode-keys vi
setw -g monitor-activity on

# Settings for X-less sessions
# set -g status-position top
set -g status-right-length 40
set -g status-left ""
set -g status-position bottom
set -g status-justify left
set -g status-bg brightblack
set -g status-fg default
# set -g status-left "#[fg=blue]mail #(ls -1 ~/mail/INBOX/new | wc -l) / #[fg=green]updates #(/home/jake/scripts/checkupdates.sh) / #[fg=magenta]volume #(pamixer --get-volume)%"
set -g status-right "#[fg=yellow]#[bg=yellow]#[fg=black] mail #(ls -1 /home/jake/mail/INBOX/new | wc -l) #{battery_status_fg}#{battery_status_bg}#[fg=black] #{battery_percentage} #[fg=magenta]#[bg=magenta]#[fg=black] %a, %b %d #[fg=blue]#[bg=blue]#[fg=black] %I:%M "
setw -g window-status-current-format '#[bg=green]#[fg=black] #I.#W #[fg=green]#[bg=brightblack]'
setw -g window-status-format '#[bg=brightblack]#[fg=green] #I.#W '

# Turn status on (we disable it in X)
set -g status on

# Load alternatives if we are in X
if-shell '[ -n "$DISPLAY" ] && echo 1' "source ~/.tmuxX.conf"

# Key bindings
bind J swap-pane -D
bind K swap-pane -U
bind l refresh-client
bind i split-window -h
bind u split-window -v
bind m set mouse
bind r source-file ~/.tmux.conf
# bind h select-pane -L # Succeeded by the Ctrl-hjkl bindings
# bind j select-pane -D
# bind k select-pane -U
# bind l select-pane -R

# Utilities
bind e split-window -l 7 /home/jake/scripts/tmux/emoji.sh
bind b split-window -l 1 /home/jake/scripts/tmux/nkjv-tmux.sh
bind B split-window -l 1 /home/jake/scripts/tmux/nkjv-tmux.sh md
bind g split-window -l 10 ddgr -n1

# Vim + tmux integration, Ctrl+hjkl magic
is_vim="ps -o state= -o comm= -t '#{pane_tty}' | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-h if-shell "$is_vim" "send-keys C-h"  "select-pane -L"
bind-key -n C-j if-shell "$is_vim" "send-keys C-j"  "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k"  "select-pane -U"
bind-key -n C-l if-shell "$is_vim" "send-keys C-l"  "select-pane -R"
bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
bind-key -T copy-mode-vi C-h select-pane -L
bind-key -T copy-mode-vi C-j select-pane -D
bind-key -T copy-mode-vi C-k select-pane -U
bind-key -T copy-mode-vi C-l select-pane -R
bind-key -T copy-mode-vi C-\ select-pane -l


# Plugin manager thing.
run -b '~/builds/tpm/tpm'
