# set prefix to control-f
set -g prefix C-f

#unbind system defined prefix
unbind C-b

# helps in faster key repetition
set -g escape-time 0

# start session number from 1 rather than 0
set -g base-index 1

# start pane number from 1 similar to windows
set -g pane-base-index 1

# Make the current window the first window
bind T swap-window -t 1

# source .tmux.conf file
bind r source-file ~/.tmux.conf \; display "Configuration Reloaded!"

# dont mess up with other ctrl-a options by pressing ctrl-a twice
bind C-a send-prefix

# vertical split
bind | split-window -h -c "#{pane_current_path}"

# horizontal split
bind - split-window -v -c "#{pane_current_path}"

#new window
bind c new-window -c "#{pane_current_path}"
# pane movement similar to vim
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# resize panes
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# to cycle through windows
bind -r C-h select-window -t :-
bind -r C-l select-window -t :+
bind b previous-window

# enable mouse
set -g mouse on

# allow mouse to select windows and panes
#set -g mouse-select-pane on
#set -g mouse-resize-pane on
#set -g mouse-select-window on

# Toggle mouse on
bind m \
    set -g mode-mouse on \;\
    set -g mouse-resize-pane on \;\
    set -g mouse-select-pane on \;\
    set -g mouse-select-window on \;\
    display 'Mouse: ON'

# Toggle mouse off
bind M \
    set -g mode-mouse off \;\
    set -g mouse-resize-pane off \;\
    set -g mouse-select-pane off \;\
    set -g mouse-select-window off \;\
    display 'Mouse: OFF'
#Note: hold shift key to select the text using mouse

# set 256 color
set -g default-terminal "screen-256color"

# monitor activities in other windows
setw -g monitor-activity on
set -g visual-activity on

# enable vi mode
setw -g mode-keys vi

# remap copy paste keys
unbind [
bind y copy-mode
unbind p
bind p paste-buffer
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection
bind-key -T copy-mode-vi r send-keys -X rectangle-toggl

# copy to system clipboard
bind C-c run "tmux save-buffer - | xclip -i -sel clipboard"

# paste from system clipboard
bind C-v run "tmux set-buffer \"$(xclip -o -sel clipboard)\"; tmux paste-buffer"

# maximizing and restoring panes
unbind Up
bind Up new-window -d -n tmp \; swap-pane -s tmp.1 \; select-window -t tmp
unbind Down
bind Down last-window \; swap-pane -s tmp.1 \; kill-window -t tmp


# switch between sessions
bind -r ( switch-client -p
bind -r ) switch-client -n

set -g default-command "/bin/fish --login"
set -g default-shell /bin/fish

# recording  program output to a log
bind P pipe-pane -o "cat >>~/#W.log" \; display "Toggled logging to ~/#W.log"


# don't allow tmux to rename the window based on commands running
set-window-option -g allow-rename off

# cool screen saver
set -g lock-after-time 3000
set -g lock-command "cmatrix -s"


# restore vim session even after shutdown
set -g @resurrect-strategy-vim "session"
# vim-tmux-focus
set -g focus-events on
set -g @continuum-save-interval '1'
# include status line powerline theme
# BEGIN FILE
# This tmux statusbar config was created by tmuxline.vim
# on Tue, 19 May 2020

set -g status-justify "centre"
set -g status "on"
set -g status-left-style "none"
set -g message-command-style "fg=colour255,bg=colour238"
set -g status-right-style "none"
set -g pane-active-border-style "fg=colour190"
set -g status-style "none,bg=colour234"
set -g message-style "fg=colour255,bg=colour238"
set -g pane-border-style "fg=colour238"
set -g status-right-length "100"
set -g status-left-length "100"
setw -g window-status-activity-style "none,fg=colour190,bg=colour234"
setw -g window-status-separator ""
setw -g window-status-style "none,fg=colour85,bg=colour234"
set -g status-left "#[fg=colour232,bg=colour154] #S #[fg=colour154,bg=colour238,nobold,nounderscore,noitalics]#[fg=colour222,bg=colour238] #W #[fg=colour238,bg=colour235,nobold,nounderscore,noitalics]#[fg=colour121,bg=colour235] #(whoami)  up: #(uptime | cut -f 4-7 -d ' ' | cut -f 1-2 -d ",") #[fg=colour235,bg=colour235,nobold,nounderscore,noitalics]"
set -g status-right "#[fg=colour235,bg=colour235,nobold,nounderscore,noitalics]#[fg=colour121,bg=colour235] %r  %a  %Y #[fg=colour238,bg=colour235,nobold,nounderscore,noitalics]#[fg=colour222,bg=colour238] #{battery_icon}#{battery_percentage}#[fg=colour154,bg=colour238,nobold,nounderscore,noitalics]#[fg=colour232,bg=colour154] #(rainbarf --battery --remaining --no-rgb)"
setw -g window-status-format "#[fg=colour234,bg=colour234,nobold,nounderscore,noitalics]#[default] #I  #W #[fg=colour234,bg=colour234,nobold,nounderscore,noitalics]"
setw -g window-status-current-format "#[fg=colour234,bg=colour238,nobold,nounderscore,noitalics]#[fg=colour255,bg=colour238] #I  #W  #F #[fg=colour238,bg=colour234,nobold,nounderscore,noitalics]"
# END FILE
#set-option -g @batt_charged_icon ""
set-option -g @batt_charging_icon "⚡"
set-option -g @batt_discharging_icon ""
set -g @online_icon "✔"
set -g @offline_icon "✗"
set-option -g status on
set-option -g status-interval 2
set-option -g status-justify "centre"
set-option -g status-left-length 60
set-option -g status-right-length 90

# Tmux plugins
set -g @tpm_plugins "              \
  tmux-plugins/tpm                 \
  tmux-plugins/tmux-sensible       \
  tmux-plugins/tmux-resurrect     \
  tmux-plugins/tmux-battery       \
  tmux-plugins/tmux-online-status     \
  tmux-plugins/tmux-yank       \
  tmux-plugins/tmux-copycat    \
  tmux-plugins/tmux-continuum    \
"

# initializes TMUX plugin manager
run-shell ~/.tmux/plugins/tpm/tpm

