# vim: ft=tmux:fdm=marker:fdl=0:noml:

# NOTE:
# -N  -> attach a note to the key
# -T  -> specify key table for the binding
# -n  -> make the binding work without the need for the prefix key
# -r  -> the key may repeat
# to remove all default bindings:
# unbind -T prefix -a
# unbind -T root -a
# unbind -T copy-mode-vi -a

# last {{{
# set -as terminal-overrides ',*:Hls=\E]8;id=%p1%s;%p2%s\E\\:Hlr=\E]8;;\E\\'

bind Z confirm-before -p "Kill all zombie (dead) panes?" \
  "run \"tmux list-panes -F '##{pane_id} ##{pane_dead}' \
    | awk '$2 == 1 { print $1 }' \
    | xargs -r -n1 tmux kill-pane -t\""

# setw -g window-status-format ' #I #[fg=white]#W #[fg=yellow]#F '
# setw -g window-status-current-format " #I:#W "
# set -g status-right ""
# set -g set-titles on
# set -g set-titles-string "#H: #W"
# set -g status-right "#{?client_prefix,#[fg=color7]#[bold]#[bg=default] - PREFIX - ,#[fg=color4]#S:#I.#P}"
set -g set-titles on
set -g set-titles-string "#H: #W"

bind r source-file ~/.config/tmux/tmux.conf \; display-message "█▓░ reloaded"
# bind ? send-keys -t.- 'less ~/.config/tmux/tmux.cheatsheet' Enter
bind m set -g mouse on \; display 'Mouse: ON'
bind M set -g mouse off \; display 'Mouse: OFF'

bind C-b if -F '#{pane_input_off}' "select-pane -e; select-pane -P bg=default" "select-pane -d; select-pane -P bg=colour237"

# session
# switch between two most recently used sessions
# bind ^ switch-client -l
# bind -n M-N switch-client -n
# bind -n M-P switch-client -p
# bind ! run-shell '(tmux switch-client -l || tmux switch-client -n) && tmux kill-session -t "#S" || tmux kill-session'
# bind S choose-session
# bind M-Tab choose-session
# bind -n M-Enter new-session
# bind -n M-s new-session

bind c new-window -c '#{pane_current_path}'
# bind C move-window -r
#bind '"' split-window -v -c "#{pane_current_path}"
#bind '%' split-window -h -c "#{pane_current_path}"
bind h split-window -h
bind v split-window

# bind Tab select-window -t :+
bind BSpace select-window -t :-

# bind n movew -r\; display "Windows renumbered."
# bind N command-prompt -p "Choose new (unused) window number:" "move-window -t %1"

bind . select-pane -t :.+

# unbind z
# bind z select-layout even-vertical
# bind Z select-layout even-horizontal
# balance-windows analogue (sort of)
# bind = select-layout even-tiled

# J: join a pane. enter source window (and, optionally, pane) ":1" or ":1.1"
bind J choose-tree -Zw "join-pane -s '%%'"
# S: send a pane to another window. enter destination window ":1" or "sessionName.:1"
bind S choose-tree -Zw "join-pane -t '%%'"

bind '"' choose-tree -Z
bind "'" choose-tree -Z -O time -r -f '#{window_active}' -f '#{?pane_active,0,1}'

# add binding for tmuxstart sessions
# bind S command-prompt -p "Make/attach session" "new-window 'tmuxstart \'%%\''"

# scroll region: scroll one line at a time (default is 5)
bind -T copy-mode-vi WheelUpPane select-pane \; send-keys -X -N 3 scroll-up
bind -T copy-mode-vi WheelDownPane select-pane \; send-keys -X -N 3 scroll-down

# send the same command to all panes/windows/sessions
# modification to only send to the current window panes
# https://scripter.co/command-to-every-pane-window-session-in-tmux/
# bind E command-prompt -p "Command:" \
#        "run \"tmux list-panes -F '##{session_name}:##{window_index}.##{pane_index}' \
#               | xargs -I PANE tmux send-keys -t PANE '%1' Enter\""
# }}}

# https://man.openbsd.org/man1/tmux.1 {{{
unbind %
bind C-a last-window
bind C-n next-window
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind r source-file ~/.tmux.conf
bind | split-window -h
bind - split-window -v
# unbind %
# bind % split-window -h -c "#{pane_current_path}"
# bind v split-window -h -c '#{pane_current_path}'
# bind s split-window -v -c '#{pane_current_path}'
set -g base-index 1
set -g clock-mode-color color33
set -g default-terminal "screen-256color"
set -g display-panes-active-color color33
set -g display-panes-color color166
set -g history-limit 15000
set -g message-style fg=color166,bg=color235
set -g mode-keys vi
set -g pane-active-border-style fg=color240
set -g pane-base-index 1
set -g pane-border-style fg=color235
set -g prefix `
set -g status-interval 20
set -g status-left " "
set -g status on
set -g status-bg default
set -g status-right-length 80
set -g status-right " #h \
#[bg=default]#[fg=color166]#(uptime|sed -e 's/.*: //g' -e 's/ //g') \
#[bg=default]#[fg=color33]%Y.%m.%d %H:%M "
set -g status-style fg=color136,bg=default
set -g window-status-bell-style fg=color235,bg=color160
set -g window-status-current-format "#[bg=color4] #W "
set -g window-status-format "#W"
set -g window-status-style fg=color244,bg=default
# }}}

# activity
# set -g bell-action none
# set -g visual-bell off
# set -g visual-silence off
# set -gw monitor-activity off

# shell | dont spawn login shell
set -g default-shell "$SHELL"

# run-shell "tmux setenv -g TMUX_VERSION $(tmux -V | perl -pe 's/[^\\d]*(\\d+\\.\\d+|\\d+)[^\\d]*/(0+$1)/ge;')"

set -g set-titles-string '#H;#S:#I.#P #W #T'

# renumber windows/sessions
set -g renumber-windows on
set-hook -g session-created "run-shell $HOME/bin/fukusu/tmux-cleanup \; run-shell $HOME/bin/fukusu/tmux-renumber-sessions"
set-hook -g session-closed "run-shell $HOME/bin/fukusu/tmux-cleanup \; run-shell $HOME/bin/fukusu/tmux-renumber-sessions"

# image preview
# if-shell -b '[ "$(echo "${TMUX_VERSION} >= 3.3" | bc)" = 1 ]' {
#   set -ga update-environment TERM
#   set -ga update-environment TERM_PROGRAM
# }

# setw -g aggressive-resize on # for grouped sessions+multi-monitor setup
# set -g synchronize-panes off # sync - switch to simultaneous pane input

set-window-option -g xterm-keys on
if "infocmp tmux-256color" {
  set -g default-terminal tmux-256color
} {
  set -g default-terminal screen-256color
}
# enable RGB color if running in xterm
# NOTE: without this, Neovim will have a weird background color.
set-option -sa terminal-overrides ",xterm*:Tc"
# use vi key bindings in copy and choice modes
setw -g mode-keys vi
# extended keys corrupting paste. disable them and synthesize <C-.> manually.
set -s extended-keys off
unbind -n C-.
# send the CSI-u sequence for Ctrl+. directly so Neovim receives it correctly.
bind -n C-. send-keys Escape "[46;5u"

# overrides {{{1
set -sa terminal-features ",xterm*:RGB"
# true colors
set -sa terminal-overrides ",xterm-256color:RGB"
set -sa terminal-overrides ',*-256color:RGB'

# clipboard | hack for mosh and osc52
set -s set-clipboard on
set -ga terminal-overrides ",$TERM:Ms=\\E]52;c;%p2%s\\7"

set -a terminal-features 'foot:RGB'
set -ga terminal-features ",foot:usstyle"

# italics/boldface/osc52 {{{2
# ms modifies OSC 52 clipboard handling to work with mosh, see
# https://gist.github.com/yudai/95b20e3da66df1b066531997f982b57b
# set -ag terminal-overrides "vte*:XT:Ms=\E]52;c;%p2%s,xterm*:XT:Ms=\E]52;c;%p2%s"
# set -ag terminal-overrides ",xterm-256color:Ms=\\E]52;c;%p2%s\\7"
# set-option -ag terminal-overrides ",xterm-256color:Ms=\\E]52;c%p1%.0s;%p2%s\\7"

# change word delimiter
# default: `!"#$%&'()*+,-./:;<=>?@[\\]^`{|}~`
# remove: `-./?%&_=+@~:` ` -_@`
set -g word-separators ' []{}|#&*()+=:;<>,?'
set -g word-separators " -_()@,[]{}:=/"

# command-alias {{{1
# custom command aliases
set-option -s command-alias[94] zoom='resize-pane -Z'
set-option -s command-alias[95] dumpv='showmsgs'
set-option -s command-alias[96] dumpenv='show-environment'
set-option -s command-alias[97] seth='set-hook'
set-option -s command-alias[98] showh='show-hooks'
set-option -s command-alias[99] dispv='display -pv'
set-option -s command-alias[100] renumber='move-window -r'

# move to another window
bind W command-prompt -p "Session name to move to:" "move-window -t '%%'"

# key {{{1
# edit tmux configuration
bind e new-window -n "~/.tmux.conf.settings" "EDITOR=\${EDITOR//mvim/nvim} && EDITOR=\${EDITOR//gvim/nvim} && \${EDITOR:-nvim} ~/.tmux.conf.settings && tmux source ~/.tmux.conf && tmux display \"~/.tmux.conf sourced\""

bind e new-window -n 'tmux.conf' 'v ~/.config/tmux/tmux.conf && tmux source ~/.config/tmux/tmux.conf && tmux display "tmux.conf sourced"'

bind e new-window -n 'tmux.conf' "sh -c \"vi ~/.config/tmux/tmux.conf && tmux source-file ~/.config/tmux/tmux.conf && tmux display 'reloaded'\""

bind e new-window "sh -c 'vi ~/.config/tmux/tmux.conf && tmux source-file ~/.config/tmux/tmux.conf && tmux display \"reloaded\"'"

bind R run-shell " \
  tmux source-file ~/.config/tmux/tmux.conf >/dev/null; \
  tmux display-message '█▓░ reloaded'"

# smart pane switching with awareness of vim splits
# see: https://github.com/christoomey/vim-tmux-navigator
is_vim='echo "#{pane_current_command}" | grep -iqE "(^|\/)g?(view|n?vim?x?)(diff)?$"'
bind -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
bind -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
bind -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
bind -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
bind -n C-\\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
bind C-w last-pane
bind C-n next-window
bind C-p previous-window

bind C-w choose-window
# bind -T root F5 select-window -p
# bind -T root F6 select-window -l
# bind -T root F8 select-window -n
# bind -T root F9 new-window
# switch back and forth between windows, screen-style.

bind C-Space last-window
bind Space send-prefix
# for nested tmux on a remote server
bind -n C-Space send-prefix

bind 0 select-window -T -t ':.$'
bind -r b select-window -t :-
bind -r n select-window -t :+
bind -n M-0 select-window -t :=0
bind -n M-1 select-window -t :=1
# bind -n M-0 choose-window

bind C-Space select-pane -t :.+
bind Tab last-pane
bind Tab select-pane -t :.+

# Disable confirmation
bind x kill-pane
bind X kill-window
bind q kill-session
bind Q kill-server

# open last session when exiting current session
set -g detach-on-destroy off

# without confirmation
bind x kill-pane

# smart pane switching with awareness of vim splits
bind -n C-k run-shell 'tmux-vim-select-pane -U'
bind -n C-j run-shell 'tmux-vim-select-pane -D'
bind -n C-h run-shell 'tmux-vim-select-pane -L'
bind -n C-l run-shell 'tmux-vim-select-pane -R'
bind -n "C-\\" run-shell 'tmux-vim-select-pane -l'

# popup-stuff
bind H run-shell ',tmux-popup htop'
bind J run-shell ',popup-tmux single'
# bind M-j run-shell ',popup-tmux master'
# bind k run-shell ',tmux-popup "note"'
# bind K run-shell ",tmux-popup '${EDITOR} ~/notes.md'"
bind T run-shell ',tmux-popup zsh'

# bind M-t run-shell ',tmux-tmp-project'

# bind M-n run-shell ',tmux-popup "pkill newsboat;newsboat -q;unreadrsstopage>/tmp/rss.html"'
# bind M-n run-shell ',tmux-popup "lf $HOME/Desktop/newsboat"'

# easier session switching
# bind -n M-o switch-client -l

# session-jump
# bind C-j split-window -v "tmux list-sessions | sed -E 's/:.*$//' | grep -v \"^$(tmux display-message -p '#S')\$\" | fzf --reverse | xargs tmux switch-client -t"

# choose-tree
# default: bind -n M-Space choose-tree
bind -n M-a choose-tree
bind -n M-w choose-tree -w
bind s choose-tree -sN
bind '"' choose-tree -Z
bind "'" choose-tree -Z -O time -r -f '#{window_active}' -f '#{?pane_active,0,1}'

# unbind n
bind n command-prompt "rename-window '%%'"
bind n command-prompt -p "Session name:" "new-session -s '%1'"

# better name management
bind c new-window -c '#{pane_current_path}' \; command-prompt "rename-window '%%'"
bind C new-window -c '#{pane_current_path}'

# bind C-b send-keys 'tat && exit' 'C-m'

# bind K confirm-before kill-pane
# bind '\' confirm-before kill-session
# bind -r -Tprefix S-Down refresh-client -D 10
# bind -n S-Down command-prompt
# bind : command-prompt
# bind S run-shell ",tmux popup -y 10 -w 100 -h 20 -E $CURRENT_DIR/bin/tmux-cht-sh.sh"

# pane {{{1
# m | change default work dir
bind m attach -c '#{pane_current_path}'

# pane swap
bind > swap-pane -D
bind < swap-pane -U

# vim pane selection - switch-pane
# bind -n C-h select-pane -L
# bind -n C-j select-pane -D
# bind -n C-k select-pane -U
# bind -n C-l select-pane -R

# bind -r -T prefix M-Down   resize-pane -D 5
# bind -r -T prefix M-Left   resize-pane -L 5
# bind -r -T prefix M-Right  resize-pane -R 5
# bind -r -T prefix M-Up     resize-pane -U 5

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

# pane resize
bind -r Left  resize-pane -L 5
bind -r Down  resize-pane -D 5
bind -r Up    resize-pane -U 5
bind -r Right resize-pane -R 5

# vim-like pane resizing
bind -r '+' resize-pane -U 5
bind -r '-' resize-pane -D 5
bind -r '<' resize-pane -L 5
bind -r '>' resize-pane -R 5

# re-blank pane title.
# useful if an ssh session has set it but you've since logged out.
bind I select-pane -T "" \; display "Title reset."
# synchronize panes -like cluster-ssh-
bind C-c setw synchronize-panes

# copy-mode {{{1
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi V send -X select-line
bind -T copy-mode-vi C-v send -X rectangle-toggle

# Copy tmux selection to system clipboard. Different mechanisms are needed for
# Linux and Mac. Allow both Enter and 'y' (for yank) to signify end selection.
# Note, use 'wl-copy' for Wayland.
bind -T copy-mode-vi y send-keys -X copy-pipe "pbcopy" \; delete-buffer
bind -T copy-mode-vi y send-keys -X copy-selection

if-shell 'case "$OS" in *Linux*) true;; *) false;; esac' \
    'bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -selection primary -i -f | xclip -selection clipboard -i"' \
    'bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel  "reattach-to-user-namespace pbcopy"'
if-shell 'case "$OS" in *Linux*) true;; *) false;; esac' \
    'bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -selection primary -i -f | xclip -selection clipboard -i"' \
    'bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel  "reattach-to-user-namespace pbcopy"'

bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi r send-keys -X rectangle-toggle
bind -T copy-mode-vi y send -X copy-pipe-and-cancel "command pbcopy"
bind -T copy-mode-vi y  send -X copy-selection-and-cancel
bind -T copy-mode-vi y  send-keys -X copy-pipe
bind -T copy-mode-vi y  send -X copy-selection-and-cancel
bind -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe "pbcopy" \; delete-buffer

# bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe "pbcopy" \; delete-buffer
# bind-key -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel "pbcopy"
# bind-key -T copy-mode-vi MouseDown3Pane select-pane # right mouse-to highlight
# bind-key -T copy-mode-vi MouseDrag3Pane select-pane \; send-keys -X begin-selection
# unbind-key -T copy-mode-vi MouseDragEnd3Pane

# make mouse drag end behavior configurable
# unbind-key -T copy-mode-vi MouseDragEnd1Pane
bind -Tcopy-mode-vi WheelUpPane select-pane \; send-keys -t '{mouse}' -X clear-selection \; send-keys -t '{mouse}' -X -N 5 scroll-up
bind -Tcopy-mode-vi WheelDownPane select-pane \; send-keys -t '{mouse}' -X clear-selection \; send-keys -t '{mouse}' -X -N 5 scroll-down

# mouse scrolling
bind -Tcopy-mode-vi WheelUpPane   select-pane \; send-keys -X -N 2 scroll-up
bind -Tcopy-mode-vi WheelDownPane select-pane \; send-keys -X -N 2 scroll-down
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M

bind -n WheelUpPane   select-pane -t= \; copy-mode -e \; send-keys -M
bind -n WheelDownPane select-pane -t= \;                 send-keys -M

# so we can scroll the mouse, select panes
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e'"

bind p paste-buffer -s ""
bind P choose-buffer "paste-buffer -b '%%' -s ''"

## yank
# transfer copied text to attached terminal with yank
bind-key -T copy-mode-vi Y send-keys -X copy-pipe 'yank > #{pane_tty}'
# transfer most-recently copied text to attached terminal with yank
bind-key -n M-y run-shell 'tmux save-buffer - | yank > #{pane_tty}'
# transfer previously copied text (chosen from a menu) to attached terminal
bind-key -n M-Y choose-buffer 'run-shell "tmux save-buffer -b \"%%%\" - | yank > #{pane_tty}"'
## yank
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel "yank" \; send-keys enter
bind-key -T copy-mode-vi 'Y' send -X copy-pipe-and-cancel "tmux loadb -" \; send-keys enter

# copy/paste to/from the system clipboard
unbind [
bind Escape copy-mode
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "wl-copy && wl-paste -n | wl-copy -p"
bind-key p run "wl-paste -n | tmux load-buffer - ; tmux paste-buffer"

# copy paste
bind [ copy-mode \; display 'copy mode'
bind -n M-[ copy-mode \; display 'copy mode'
bind ] paste-buffer
bind C-] choose-buffer

bind -Tcopy-mode-vi ? command-prompt -p 'search-backward:' -I '#{pane_search_string}' -i 'send-keys -X search-backward-incremental "%%%"'
bind -Tcopy-mode-vi / command-prompt -p 'search-forward:' -I '#{pane_search_string}' -i 'send-keys -X search-forward-incremental "%%%"'

# turn on incremental search in vi mode
bind -Tcopy-mode-vi ? command-prompt -i -I "#{pane_search_string}" -T search -p "(search up)" { send-keys -X search-backward-incremental "%%" }
bind -Tcopy-mode-vi / command-prompt -i -I "#{pane_search_string}" -T search -p "(search down)" { send-keys -X search-forward-incremental "%%" }

# make "/" and "?" work without going into copy mode first.
bind / {
  copy-mode -H
  command-prompt -i -I "#{pane_search_string}" -T search -p "(search down)" {
    send-keys -X search-forward-incremental "%%"
  }
}
bind ? {
  copy-mode -H
  command-prompt -i -I "#{pane_search_string}" -T search -p "(search up)" {
    send-keys -X search-backward-incremental "%%"
  }
}
# jump search mode with prefix
bind '/' copy-mode \; send-keys "/"
bind '?' copy-mode \; send-keys "?"

# jump search mode with prefix | search buffer by /
bind -Tcopy-mode-vi '/' copy-mode \; send-keys "/"
bind -Tcopy-mode-vi '?' copy-mode \; send-keys "?"

# mouse {{{1
# double/triple click
# work outside of copy mode (already works inside it with default bindings)
bind -T root DoubleClick1Pane if-shell -Ft'{mouse}' '#{alternate_on}' \
  "send-keys -M" {
    copy-mode -t'{mouse}' -H
    send-keys -t'{mouse}' -X select-word
  }
bind -T root TripleClick1Pane if-shell -Ft'{mouse}' '#{alternate_on}' \
  "send-keys -M" {
    copy-mode -t'{mouse}' -H
    send-keys -t'{mouse}' -X select-line
  }
# dont exit copy mode on double or triple click.
bind -Tcopy-mode-vi DoubleClick1Pane if-shell -Ft'{mouse}' '#{alternate_on}' \
  "send-keys -M" {
    copy-mode -t'{mouse}' -H
    send-keys -t'{mouse}' -X select-word
  }
bind -Tcopy-mode-vi TripleClick1Pane if-shell -Ft'{mouse}' '#{alternate_on}' \
  "send-keys -M" {
    copy-mode -t'{mouse}' -H
    send-keys -t'{mouse}' -X select-line
  }

# style {{{1
set -g status-interval 30
set -g status-justify left
set -g status-left-length 40
set -g status-right-length 140
set-option -g status-position bottom
tm_session_name="#{session_group}" # since we are attaching single session to multiple teminals #S is not the best idea
tm_battery="#(,tmux-battery)"
# tm_load="#(,tmux-load)"
tm_fullscreen="#(,tmux-iszoomed)"
set -g status-right '#[fg=colour001]'$tm_load' #[fg=yellow]'$tm_fullscreen' #[fg=green]'$tm_session_name' '
set -g status-left ' '

set -g pane-border-style 'fg=color252'
set -g message-command-style 'fg=color252,bg=color1'
# window
setw -g mode-style 'fg=color254,bg=color4'
setw -g window-status-bell-style 'fg=color1,bg=default'
setw -g window-status-style 'fg=color245,bg=default'
# setw -g window-status-format "#[fg=color245] #W "
setw -g window-status-current-format "#[fg=color4] #W "
set-window-option -g window-status-format         ' #I#F#[nobold]#W '
set-window-option -g window-status-current-format ' #[bold]#I#F#[nobold]#W '
# statusbar
# set -g status-justify left
# set -g status-left-length 20
set -g status-right-length 50
set -g status-position bottom

# tm_pane="#[default,bg=default, fg=red]  #P"
# set -g status-right "$tm_pane $tm_prefix"
# set -g status-right '#{?client_prefix,#[fg=white]#[bg=red]#[bold] - PREFIX - ,#[fg=brightwhite]#H'

# statusbar modules {{{2
tm_upTime="#[default,fg=red,bg=white] #(,tmux-pretty-time)"
set -g status-right "$tm_upTime"

# set -g status-right "$tm_pane $tm_upTime $tm_mem $tm_cpu $tm_date"
# set -g status-left "#[default,bg=$base00,fg=$base0F]  #S "
# tm_date="#[fg=color4] %Y-%m-%d %I:%M %p "
# tm_cpu=" #(,tmux-cpu)"
# tm_mem=" #(,tmux-mem)"
# tm_prefix="#{prefix_highlight}"
# tm_upTime="#[default,fg=$base07,bg=$base00] #(,tmux-pretty-time)"
# tm_prefix_whost="#{?client_prefix,#[fg=white]#[bg=red]#[bold] - PREFIX - ,#[fg=brightwhite]#H}"
# tm_tailnet="#(,tmux-tailscale-status)"

# only show status bar if there is more then one window
# set -g status off
# set-hook -g after-new-window  'if "[ #{session_windows} -gt 1 ]" "set status on"'
# set-hook -g after-kill-pane   'if "[ #{session_windows} -lt 2 ]" "set status off"'
# set-hook -g pane-exited       'if "[ #{session_windows} -lt 2 ]" "set status off"'
# set-hook -g window-layout-changed 'if "[ #{session_windows} -lt 2 ]" "set status off"'


# ssh_client {{{1
# # use different mapping when in docker or ssh session
# if -b '[ -n "$SSH_CLIENT" ] || [ -f /.dockerenv ]' { \
#     set -g status-position top
#     set -g prefix M-q
#     bind    M-q resize-pane -Z
#     bind    M-p previous-window
#     bind    M-n next-window
#     bind -n M-Left previous-window
#     bind -n M-Right next-window
#     bind    M-w run-shell -b "~/.tmux/plugins/tmux-fzf/scripts/session.sh attach"
# } {
#     set -g status-position bottom
#     set -g prefix C-q
#     bind    C-q resize-pane -Z
#     bind    C-p previous-window
#     bind    C-n next-window
#     bind -n C-Left previous-window
#     bind -n C-Right next-window
#     bind    C-w run-shell -b "~/.tmux/plugins/tmux-fzf/scripts/session.sh attach"
# }
# osx {{{1
# if-shell "command -v 'reattach-to-user-namespace' >/dev/null" "set -g default-command 'reattach-to-user-namespace -l $SHELL'"
if-shell 'test "$OS" = "darwin"' \
  'set -g default-command "reattach-to-user-namespace -l $SHELL"' \
  'bind -T copy-mode-vi y send-keys -X copy-pipe "reattach-to-user-namespace pbcopy"'

# {{{
# if-shell "test \"\$(uname)\" = Darwin" "source-file ~/.config/tmux/tmux_osx.conf"
if-shell "type 'reattach-to-user-namespace' >/dev/null" "set -g default-command 'reattach-to-user-namespace -l $SHELL'"
# open a new terminal in cwd
bind C-n run-shell -b "$HOME/bin/terminal -d #{pane_current_path} -- tmux -u new -c #{pane_current_path} zsh"
# }}}
# }}}1

# tmux.conf.local
if-shell "test -e ~/.tmux.conf.local" "source-file ~/.tmux.conf.local"

# create a single default session - because a session is created here
# tmux should be started with "tmux attach" rather than "tmux new"
new -d -s0 -nirssi 'exec irssi'
set -t0:0 monitor-activity on
set -t0:0 aggressive-resize on
neww -d -ntodo 'exec emacs ~/TODO'
setw -t0:1 aggressive-resize on
neww -d -nmutt 'exec mutt'
setw -t0:2 aggressive-resize on
neww -d
neww -d
neww -d
