##############################
# _
# | |_ _ __ ___ _ ___ __
# | __| '_ ` _ \| | | \ \/ /
# | |_| | | | | | |_| |> <
# \__|_| |_| |_|\__,_/_/\_\
#
#############################
############################################################################
############################################################################
# Reset Prefix
############################################################################
set -g prefix C-t
bind-key t send-prefix # for nested tmux sessions
############################################################################
# Global options
############################################################################
# large history
set-option -g history-limit 10000
#for functional copy/paste support without having to use hackery
#must install reattach-to-user-namespace via homebrew: brew install reattach-to-user-namespace
bind-key C-c run-shell 'tmux save-buffer - | reattach-to-user-namespace pbcopy'
bind-key C-v run-shell 'reattach-to-user-namespace pbpaste | tmux load-buffer - \; paste-buffer -d'
## update the TERM variable of terminal emulator when creating a new session or attaching a existing session
set -g update-environment 'DISPLAY SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY TERM'
## determine if we should enable 256-colour support
if "[[ ${TERM} =~ 256color || ${TERM} == fbterm ]]" 'set -g default-terminal screen-256color'
# basic settings
set-window-option -g xterm-keys on # for vim
set-window-option -g mode-keys emacs
set-window-option -g monitor-activity on
set-window-option -g window-status-current-style fg=white,bg=default,reverse
# Automatically set window title
setw -g automatic-rename
set -g mouse
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
############################################################################
# Status Bar
############################################################################
set-option -g status-justify centre
set-option -g status-bg black # colour213 # pink
set-option -g status-fg cyan
set-option -g status-interval 5
set-option -g status-left-length 75
set-option -g status-right-length 100
set -g @net_speed_interfaces "en0 en8"
set-option -g status-left '#[fg=magenta]ยป #[fg=blue,bold]#S#[default]:#{online_status}#{net_speed} #{tmux_mode_indicator} #{pomodoro_status}'
set-option -g status-right '#[fg=green,bg=default,bright]#(tmux-mem-cpu-load --colors --powerline-left --interval 2) #[fg=cyan]#(id -un) #[fg=colour57]%a %m/%d %H:%M %z#[default]'
set-option -g visual-activity on
#set-option -g status-left "#(~/clones/tmux-powerline/powerline.sh left)"
#set-option -g status-right "#(~/clones/tmux-powerline/powerline.sh right)"
set-hook -g session-created 'run-shell "~/clones/tmux-powerline/powerline.sh init"' # prettifies the window-status segments
#run-shell "powerline-daemon -q"
#source /usr/share/powerline/bindings/tmux/powerline.conf
# Titles (window number, program name, active (or not)
set-option -g set-titles on
set-option -g set-titles-string '#H:#S.#I.#P #W #T'
############################################################################
# Unbindings
############################################################################
#unbind [ # copy mode bound to escape key
unbind j
unbind C-b # unbind default leader key
unbind '"' # unbind horizontal split
unbind % # unbind vertical split
############################################################################
# Bindings
############################################################################
# reload tmux conf
bind-key r source-file ~/.tmux.conf
#bind Escape copy-mode
# new split in current pane (horizontal / vertical)
bind-key - split-window -v # split pane horizontally
bind-key \\ split-window -h # split pane vertically
# break-pane
bind-key Enter break-pane
# join-pane [-dhv] [-l size | -p percentage] [-s src-pane]
# [-t:dst-window.dst-pane] (destination window (dot) destination pane
# (alias: joinp)
#
#bind C-j command-prompt "joinp"
#bind C-j command-prompt "join-pane"
#bind-key j command-prompt "join-pane -s '%%'"
#bind-key j command-prompt "joinp -t:0"
bind-key Space command-prompt "joinp -t:%%" # %% = prompt for window.pane [-V|H] # vert|hor split
#previous pane
bind-key -n C-up prev
bind-key -n C-left prev
#next pane
bind-key -n C-right next
bind-key -n C-down next
############################################################################
# windows
############################################################################
set-window-option -g window-status-current-style bg=red
bind C-j previous-window
bind C-k next-window
bind-key C-a last-window # C-a C-a for last active window
bind A command-prompt "rename-window %%"
# By default, all windows in a session are constrained to the size of the
# smallest client connected to that session,
# even if both clients are looking at different windows.
# It seems that in this particular case, Screen has the better default
# where a window is only constrained in size if a smaller client
# is actively looking at it.
setw -g aggressive-resize on
############################################################################
# panes
############################################################################
# Navigation ---------------------------------------------------------------
# use the vim motion keys to move between panes
bind-key h select-pane -L
bind-key j select-pane -D
bind-key k select-pane -U
bind-key l select-pane -R
# Resizing ---------------------------------------------------------------
bind-key C-h resize-pane -L
bind-key C-j resize-pane -D
bind-key C-k resize-pane -U
bind-key C-l resize-pane -R
# use vim motion keys while in copy mode
#setw -g mode-keys vi
############################################################################
# layouts
############################################################################
bind o select-layout "active-only"
bind M-- select-layout "even-vertical"
bind M-| select-layout "even-horizontal"
bind M-r rotate-window
############################################################################
# Plugins
############################################################################
# List of plugins
set -g @plugin 'tmux-plugins/tmux-colors-solarized'
set -g @colors-solarized 'dark'
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugs/tmux-scroll-copy-mode'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @resurrect-capture-pane-contents 'on'
set -g @plugin 'tmux-plugins/tmux-sidebar'
set -g @plugin 'tmux-plugins/tmux-online-status'
set -g @plugin 'tmux-plugins/tmux-copycat'
set -g @plugin 'tmux-plugins/tmux-fingers'
set -g @plugin 'b0o/tmux-autoreload'
set -g @plugin 'jaclu/tmux-power-zoom'
set -g @plugin 'olimorris/tmux-pomodoro-plus'
set -g @plugin '27medkamal/tmux-session-wizard'
set -g @plugin 'MunifTanjim/tmux-mode-indicator'
set -g @plugin 'MunifTanjim/tmux-suspend'
set -g @plugin 'tmux-plugins/tmux-net-speed'
#done via antigen instead
#set -g @plugin 'thewtex/tmux-mem-cpu-load'
set -g @net_speed_interfaces "en0"
set -g @net_speed_format " D:%10s U:%10s"
#run-shell '~/.tmux/plugins/tmux-home/home.tmux'
# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'git@github.com/user/plugin'
# set -g @plugin 'git@bitbucket.com/user/plugin'
# # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'