Files
config/tmux.conf
T

340 lines
17 KiB
Bash

# --------------------------------------------------------------------------- #
# #
# Module: tmux.conf By: sohorx <banlin.adrien@gmail.com> #
# #
# Created: 2015/04/01 18:17:25 Updated: 2016/04/01 18:17:25 #
# #
# --------------------------------------------------------------------------- #
# Note: {{{ #
# minimalist tmux configuration which behave a bit like vi #
# }}} #
# --------------------------------------------------------------------------- #
# Global options: {{{
# --------------
set -g bell-action none # make it Shut up!
set-option -g default-shell $SHELL # set shell
set -g default-terminal "screen-256color" # term colors
#set -ga terminal-overrides ",*256col*:Tc" # term cap only
set -ga terminal-overrides '*:Ss=\E[%p1%d q:Se=\E[ q,*256col*:Tc' # cursor control
setw -g mode-keys vi # vi mode
set -s escape-time 1 # Fix terminal name issues
set -g set-titles on # Turn on window titles
setw -g automatic-rename on # Automatically set window title
set -g mouse on # mouse cap
set-window-option -g clock-mode-colour brightwhite # set colour clock
set -g focus-events on # for vim (?)
set-option -g automatic-rename on # auto rename session
set-option -g status-interval 5 # rename session interval
set -g status on # enable status bar at start
# https://github.com/3rd/image.nvim/?tab=readme-ov-file#tmux
set -gq allow-passthrough on # image.nvim requirements
set -g visual-activity off # image.nvim requirements
# ------------------------------------------------------------------------- }}}
# Change default strings: {{{
# ----------------------
# Set window title string
set -g set-titles-string '#S :: #W :: #F#P #{pane_current_command}'
#set-option -g automatic-rename-format "#{b:pane_current_path}"
# ------------------------------------------------------------------------- }}}
# Variables: {{{
# ---------
is_vim='echo "#{pane_current_command}" | grep -iqE "(^|\/)g?(view|n?vim?)(diff)?$"'
# is_vim Note: {{{
# The pane's foreground command, as tmux sees it. The older variant read a
# "@tmux_vim_<pane>" variable that a vim plugin had to set; nothing sets it
# here, so C-h/j/k/l never reached vim.
# }}}
resurrect_root_dir="$XDG_CACHE_HOME/tmux/resurect"
# chunk of status bar variables and coloration
#sep_st='#[fg=brightwhite,bg=brightblue]'
#sep_c='#[fg=black]'
#
#sep_d='#[fg=brightwhite,bold]'
#sep_e='#[default,fg=brightblack]#[bg=brightblack]#[fg=brightwhite]'
#sep_f='#[fg=black]'
#
#sep_g='#[fg=blue,bold]'
#sep_h='#[default,fg=brightwhite]#[fg=blue,bg=brightwhite,bold]'
#sep_i='#[default,bg=brightwhite,fg=black]'
#
#sep_b='#[fg=brightyellow]#[default, bg=brightyellow, fg=black]'
#sep_a='#[fg=yellow]#[bg=yellow, fg=black]'
#
#sep_off="#[fg=brightred]#[bg=brightred, fg=brightwhite, bold] OFF"
#sep_on="#[fg=green]#[bg=green, fg=brightwhite, bold] ON"
#
#brightwhite_fg="#[fg=brightwhite]"
##
sep_st='#[fg=brightwhite,bg=brightblue]'
sep_c='#[fg=black] '
sep_d='#[fg=brightwhite,bold] '
sep_e='#[default,fg=brightblack] #[bg=brightblack]#[fg=brightwhite]'
sep_f='#[fg=black]'
sep_g='#[fg=brightblue,bold] '
sep_h='#[default,fg=brightwhite] #[fg=black,bg=brightwhite,bold]'
sep_i='#[default,bg=brightwhite,fg=black]'
sep_b='#[fg=brightyellow] #[default, bg=brightyellow, fg=black]'
sep_a='#[fg=yellow] #[bg=yellow, fg=black]'
sep_off="#[fg=brightred] #[bg=brightred, fg=brightwhite, bold] OFF"
sep_on="#[fg=green]#[bg=green, fg=brightwhite, bold] ON"
brightwhite_fg="#[fg=brightwhite]"
# ------------------------------------------------------------------------- }}}
# Key bindings: {{{
# ------------
# Unbindings
unbind [
unbind C-b # (prefix)
unbind C-n # (nav)
unbind l
unbind C-p
unbind v # (selection)
unbind y # (copy)
unbind p # (pasting)
unbind % # (sp)
unbind '"' # (vs)
unbind-key -T copy-mode-vi MouseDragEnd1Pane # (mouse setting) {{{
# stock binding = "release the drag: copy AND leave copy-mode", which loses
# the selection on screen. Rebound below (clipboard section) as copy without
# leaving, so a drag is enough and y stays available.
# ref: https://github.com/tmux/tmux/issues/140
# }}}
set -g prefix C-a # bind screen like prefix
bind C-a send-prefix # C-a C-a = literal C-a (shell home)
# specific commands
bind-key C-o command-prompt "new-session -s %1 -c ~"
bind R source-file ~/.config/tmux/tmux.conf \; display-message "Config reloaded..."
# Resizing key bindings (same arrow layout as the moves below, with prefix)
bind-key -r C-u resize-pane -U 5
bind-key -r C-h resize-pane -L 5
bind-key -r C-j resize-pane -D 5
bind-key -r C-k resize-pane -R 5
bind-key -r C-n next-window \; set status on
bind-key -r C-p previous-window \; set status on
# Alt+arrow too (no prefix): native on Linux/PC. On macOS iTerm2 sends Esc b/f
# for Option+arrow, so map Cmd+arrow there to the xterm Alt+arrow sequences
# (Send Escape Sequence `[1;3D` / `[1;3C`); it then shadows iTerm2's own
# Cmd+arrow tab switching in that profile (Cmd+Shift+[ ] still work).
bind-key -n M-Left previous-window \; set status on
bind-key -n M-Right next-window \; set status on
# Moving across panes (and vim), no prefix: ctrl + u/h/j/k laid out as arrows
# (u up, h left, j down, k right). These keys sit at the same place on AZERTY
# and QWERTY US, and need no option key. Each one still reaches vim when vim
# runs in the pane. C-l is free, so it clears the shell screen again.
# Shell cost: C-u (readline "clear the line") is taken.
bind -n C-u if-shell "$is_vim" "send-keys C-u" "select-pane -U"
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 -R"
# Copy-mode has its own key table, where stock tmux turns these keys into text
# navigation (C-h cursor-left, C-u halfpage-up, C-j copy). Arrows do that job;
# the four keys keep switching panes there too.
bind -T copy-mode-vi C-u select-pane -U
bind -T copy-mode-vi C-h select-pane -L
bind -T copy-mode-vi C-j select-pane -D
bind -T copy-mode-vi C-k select-pane -R
# Ctrl+Alt+arrow too (no prefix), straight to the pane, no vim pass-through.
# Native on Linux/PC; on macOS map Ctrl+Cmd+arrow in iTerm2 to the xterm
# Ctrl+Alt+arrow sequences (Send Escape Sequence `[1;7A` `[1;7B` `[1;7D` `[1;7C`).
bind -n C-M-Up select-pane -U
bind -n C-M-Down select-pane -D
bind -n C-M-Left select-pane -L
bind -n C-M-Right select-pane -R
bind -T copy-mode-vi C-M-Up select-pane -U
bind -T copy-mode-vi C-M-Down select-pane -D
bind -T copy-mode-vi C-M-Left select-pane -L
bind -T copy-mode-vi C-M-Right select-pane -R
bind Escape copy-mode # bind vi-like 'normal' mode
bind -Tcopy-mode-vi 'v' send -X begin-selection # bind vi-like visual mode
# Clipboard: pbcopy/pbpaste on macOS. Elsewhere tmux's own buffer, which tmux
# also hands to the terminal through OSC 52 (set-clipboard), so it reaches the
# local clipboard over ssh. xsel/xclip dropped: headless servers have no X.
# Releasing a mouse drag copies too (selection kept on screen, copy-mode stays).
# alt+c (in a selection) = y, alt+v (anywhere, no prefix) = prefix p: cmd-less
# keyboards. GNOME Terminal: keep "Enable mnemonics" off or alt+v opens View.
# A finished drag also marks the pane (@mouse_sel): from then on any bare key
# leaves copy-mode, see the hook below and the run-shell at the end of file.
if-shell 'command -v pbcopy >/dev/null' \
'bind -Tcopy-mode-vi y send -X copy-pipe-and-cancel pbcopy ; bind -Tcopy-mode-vi M-c send -X copy-pipe-and-cancel pbcopy ; bind -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-pipe-no-clear pbcopy \; set -p @mouse_sel 1 ; bind p run "pbpaste | tmux load-buffer - ; tmux paste-buffer" ; bind -n M-v run "pbpaste | tmux load-buffer - ; tmux paste-buffer"' \
'bind -Tcopy-mode-vi y send -X copy-selection-and-cancel ; bind -Tcopy-mode-vi M-c send -X copy-selection-and-cancel ; bind -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-selection-no-clear \; set -p @mouse_sel 1 ; bind p paste-buffer ; bind -n M-v paste-buffer'
bind-key -Tcopy-mode-vi Escape send -X cancel # cancel v mode
bind-key -Tcopy-mode-vi ^v send -X rectangle-toggle # cancel v mode
# Wheel: stock tmux scrolls 5 lines per tick, too fast on a trackpad (one flick =
# dozens of ticks). Halved to 2; applies to history scrolling (copy-mode) only.
bind -T copy-mode-vi WheelUpPane select-pane \; send-keys -X -N 2 scroll-up
bind -T copy-mode-vi WheelDownPane select-pane \; send-keys -X -N 2 scroll-down
bind-key -T copy-mode-vi MouseDown1Pane select-pane -t = \; send-keys -X clear-selection
bind-key -T copy-mode-vi MouseUp1Pane select-pane -t = \; send-keys -X cancel
bind -n MouseDrag1Pane if -Ft= '#{mouse_any_flag}' 'if -Ft= "#{pane_in_mode}" "copy-mode -eM" "send-keys -M"' 'copy-mode -eM'
# (note) {{{
# A plain click (MouseDown then MouseUp, no drag) leaves copy-mode: back to
# the prompt, selection dropped. A drag sends MouseDrag/MouseDragEnd instead
# of MouseUp, so it keeps the scroll position and selects as usual. A click
# on another pane still switches to it.
# The `bind -n MouseDrag1Pane if -Ft= ...` changes the default binding of
# MouseDrag1Pane, the only difference is that we use `copy-mode -eM` instead
# of `copy-mode -M`, so that WheelDownPane can trigger copy-mode to exit when
# copy-mode is entered by MouseDrag1Pane
# Inner quotes stay plain: `\"` is literal inside '...' since tmux 3.0, and the
# mouse-app branch (claude, vim) then dies with "syntax error" on every drag.
# }}}
# @mouse_sel (set by MouseDragEnd1Pane above) must not outlive the copy-mode
# it was set in, whatever way that mode ends: cleared when the pane leaves it.
set-hook -g pane-mode-changed 'if -F "#{!:#{pane_in_mode}}" "set -pu @mouse_sel"'
bind-key k "split-window -v -b -c '#{pane_current_path}'"
bind-key h "split-window -h -b -c '#{pane_current_path}'"
bind-key j "split-window -v -c '#{pane_current_path}'"
bind-key l "split-window -h -c '#{pane_current_path}'"
bind-key i "split-window -h -c '#{pane_current_path}'" # i: side by side (vertical bar)
bind-key - "split-window -v -c '#{pane_current_path}'" # -: stacked (horizontal bar)
# Move panes between windows and around. Source = the marked pane (prefix m,
# toggles) when one is set, else the current pane. Prefix ! (stock break-pane)
# does the reverse: current pane out to a new window.
bind-key J join-pane -v # marked pane joins this window, below (mirrors j)
bind-key L join-pane -h # marked pane joins this window, beside (mirrors l)
bind-key S swap-pane # swap marked pane with the current one
# Stock { } (swap-pane -U/-D) sit behind alt+( alt+) on a Mac AZERTY keyboard.
# ( ) are unshifted there, and repeatable; they replace switch-client -p/-n,
# which prefix s (choose-tree) still covers.
bind-key -r ( swap-pane -U # move pane up / left (previous slot)
bind-key -r ) swap-pane -D # move pane down / right (next slot)
bind q kill-window # Kill window
bind Q kill-session # Kill the session (not server)
bind C-c neww \; set status on # enable status bar
bind c neww \; set status on # disable status bar
# Enable disable bindings and change status bar with it {{{
bind -T root F10 set status off
bind -T root F9 set status on
bind -T root F12 \
set prefix None \; \
set key-table off \;\
set focus-events off \; \
set status-right '#{brightwhite_fg} #h #{sep_b} %a %d/%m/%Y #{sep_a} %H:%M #{sep_off} : #{continuum_status} ' \;\
set status on\; \
refresh-client -S\;
bind -T off F11 \
set -u prefix \;\
set -u key-table \;\
set -u focus-events \;\
set status-right '#{brightwhite_fg} #h #{sep_b} %a %d/%m/%Y #{sep_a} %H:%M #{sep_on} : #{continuum_status} ' \;\
set status on\;\
refresh-client -S\;
# }}}
# ------------------------------------------------------------------------- }}}
# Plugins: {{{
# -------
# To make plugins works, the run tpm must be done by the main file.
#
# run '~/.config/tmux/plugins/tpm/tpm'
##
set -g @tpm_plugins ' \
tmux-plugins/tpm \
ofirgall/tmux-window-name \
tmux-plugins/tmux-sensible \
tmux-plugins/tmux-resurrect \
tmux-plugins/tmux-continuum \
'
# plugins options
set -g @resurrect-strategy-vim 'session'
set -g @resurrect-capture-pane-contents 'on'
set -g @resurrect-processes ' \
irb \
ipython \
~ranger \
pry \
ri \
"~bundle exec ri" \
"~bundle exec pry" \
"~pipenv shell" \
"~pipenv run" \
glow \
"~vaas-infra ssh" \
"~vaas-cli -s vaas-infra.dev.alphalink.fr ssh" \
ssh \
mosh \
tig \
'
set -g @resurrect-strategy-session 'always'
set -g @continuum-restore 'on'
set -g @continuum-save-interval '15' # save every minutes
set -g @resurrect-dir "$XDG_CACHE_HOME/tmux/$TMUX_SOCKET_NAME"
# ------------------------------------------------------------------------- }}}
# Status Bar: {{{
# ----------
set -wg mode-style bg=yellow,fg=black # selection: same accent as the status bar
set-window-option -g window-status-separator ' ' # one blank between tabs
set -g status-position bottom
set -g status-left-length 42
set -g status-right-length 80
# Tabs sit in the true middle of the screen, whatever status-left/right take.
set -g status-justify absolute-centre
#setw -g status-style bg=black
setw -g status-style bg=default
set -g status-left '#{sep_st} λ #S #{sep_c}'
# setw -g window-status-format '#{sep_d} #I #{sep_e} #W #{sep_f}'
# setw -g window-status-current-format '#{sep_g} #I #{sep_h} #W #{sep_i}'
# set -g status-right '#{brightwhite_fg} #h #{sep_b} %a %d/%m/%Y #{sep_a} %H:%M #{sep_on} : #{continuum_status} '
# Tabs: index + name, padded; the current one is bold on a light pill.
setw -g window-status-format '#{sep_e} #I #W #{sep_f}'
setw -g window-status-current-format '#{sep_h} #I #W #{sep_i}'
set -g status-right '#{sep_b} #h #{sep_e}#{sep_on} : #{continuum_status} '
# set Panel borders
set -g pane-active-border-style fg=white,bg=white
set -g pane-border-style fg=white,bg=default
# Dim inactive panes: only cells in "default" colour change (coloured text and
# vim's own background stay as they are). The active style must repeat the
# terminal colours: since tmux 3, "default" there inherits window-style, so
# the active pane would be dimmed too. Values = iTerm2 Default profile, dark
# mode (fg #dcdcdc, bg #15191f); a light theme needs the opposite.
set -g window-style fg=#a6acb6,bg=#353d48
set -g window-active-style fg=#dcdcdc,bg=#15191f
# set Message text
set-option -g message-style bg=default,fg=red
set-option -g message-command-style bg=default,fg=brightwhite
# ------------------------------------------------------------------------- }}}
run '~/.config/tmux/plugins/tpm/tpm'
# After a mouse selection any bare key leaves copy-mode (keyboard/wheel
# copy-mode keeps its vi keys). Wraps the bindings as they stand, so it runs
# last, after the plugins. Script deployed by install.sh with the other bins.
run-shell '~/.local/bin/tmux-copy-exit-keys'