## user experience related stuff

# preserve some environment variables
set-option -g update-environment "REAL_TERM"

# fix delay between switching modes in vim
set -sg escape-time 20

# remap prefix
unbind C-b
set -g prefix M-q
bind M-q send-prefix

# make colors display correctly
set -g default-terminal "tmux-256color"
set -ag terminal-overrides ",*:RGB"

# set cursor style to underline
set -g cursor-style "underline"

# avoid setting cursor back to block after detaching tmux
set -ag terminal-overrides ",*:Se=\e[4 q"

# undercurl support
set -ag terminal-overrides ',*:Smulx=\E[4::%p1%dm'

# support colors for undercurl
set -ag terminal-overrides ',*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m'

# set scrollback buffer to 10000
set -g history-limit 10000

# customize the status line
set -g status-fg colour2
set -g status-style bg=default

# disable mouse
set -g mouse off

# enable clipboard
set -g set-clipboard on
set -ag terminal-overrides ",*:clipboard"

# emacs keybindings
# set -g mode-keys emacs
# set -g status-keys emacs
# bind -Tcopy-mode C-w send -X copy-pipe-and-cancel 'xsel --clipboard --input'
# bind -Tcopy-mode M-w send -X copy-pipe-and-cancel 'xsel --clipboard --input'

# vi keybindings
set -g mode-keys vi
set -g status-keys vi

# copy & paste settings
bind-key -T copy-mode-vi v send -X begin-selection
bind-key -T copy-mode-vi V send -X select-line
bind-key -T copy-mode-vi y send -X copy-pipe-and-cancel 'wl-copy'

# status bar configuration
set -g status-right-length 100
set -g status-left-length 50
set -g status-right "#{pomodoro_status} #{@mode_indicator_suspend}#{?window_bigger,[#{window_offset_x}#,#{window_offset_y}] ,}\"#{=21:pane_title}\""

# urlscan
bind-key u run "tmux popup -E -b double -w 100% -h 40% -y 0 \
                  sh -c 'tmux capture-pane -Jp | urlscan -d -c' "

## tmux plugins related stuff

# list of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-pain-control'
set -g @plugin 'MunifTanjim/tmux-suspend'
set -g @plugin 'rafi/tmux-pass'
set -g @plugin 'olimorris/tmux-pomodoro-plus'

# tmux-suspend
set -g @suspend_suspended_options " \
  @mode_indicator_suspend::[*] "
set -g @suspend_key 'F12'

# tmux-pass
set -g @pass-copy-to-clipboard off
set -g @pass-hide-pw-from-preview on
set -g @pass-hide-preview on

# tmux-pomodoro-plus
set -g @pomodoro_on " 🍅 "                     # The formatted output when the Pomodoro is running
set -g @pomodoro_complete " ✔︎ "                # The formatted output when the break is running
set -g @pomodoro_pause " ⏸︎ "                   # The formatted output when the Pomodoro/break is paused
set -g @pomodoro_prompt_break " ⏲︎ break?"      # The formatted output when waiting to start a break
set -g @pomodoro_prompt_pomodoro " ⏱︎ start?"   # The formatted output when waiting to start a Pomodoro

set -g @pomodoro_mins 25                       # The duration of the Pomodoro
set -g @pomodoro_break_mins 5                  # The duration of the break after the Pomodoro completes
set -g @pomodoro_intervals 4                   # The number of intervals before a longer break is started
set -g @pomodoro_long_break_mins 25            # The duration of the long break

set -g @pomodoro_sound 'off'                   # Sound for desktop notifications (Run `ls /System/Library/Sounds` for a list of sounds to use on Mac)
set -g @pomodoro_notifications 'on'            # Enable desktop notifications from your terminal
set -g @pomodoro_interval_display " [%s/%s]"

# automatically install tpm and tmux plugins when tmux is started
if "test ! -d ~/.tmux/plugins/tpm" \
   "run 'git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm && ~/.tmux/plugins/tpm/bin/install_plugins'"

# initialize tmux plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
