Ben Grande 45a0acb222
feat: support truecolor
- Standardize capability usage with the terminfo database for
  portability. POSIX tput does declare only the basic options such as
  'init', 'reset' and 'clear', leaving the rest unspecified, that is not
  ideal but hard coding escape sequences is way worse.
- Set colorization options based on number of colors the terminal
  supports and not the TERM variable when possible. This is incomplete,
  terminal emulators may support or adapt more than it is advertised,
  but involves using DECRQSS queries and delays, as an example, 'resize'
  utility from XTerm uses 3 seconds as delay, this is worrisome.
- Term with only '-direct' variants without ending with 256 means it
  only supports direct-color indexing, therefore 'tmux-direct' cannot be
  used, but the non-multiplexer terminal 'xterm-direct256' can.
2025-03-27 11:42:50 +01:00

148 lines
5.6 KiB
Bash

## tmux.conf
## SPDX-FileCopyrightText: 2023 - 2025 Benjamin Grande M. S. <ben.grande.b@gmail.com>
##
## SPDX-License-Identifier: AGPL-3.0-or-later
#! {{{ Options
## Usage
set-window-option -g wrap-search off
set-window-option -g aggressive-resize on
set-window-option -g pane-base-index 1
set-option -g base-index 1
set-option -g status-keys emacs
set-option -g mode-keys vi
set-option -g mouse on
set-option -g history-limit 10000
set-option -g repeat-time 2000
set-option -g escape-time 50
set-option -g status-position top
run-shell '\
colors=$(tput colors) || true 2>/dev/null; \
if test "$colors" -lt 256; then \
tmux set-option -g default-terminal tmux; \
elif test "$colors" -ge 256; then \
tmux set-option -g default-terminal tmux-256color; \
fi'
set-option -g display-panes-time 2000
set-option -g display-time 2000
set-option -g focus-events on
set-option -g status-interval 5
set-option -g set-titles on
## Visual
set-option -g display-panes-active-colour 'red'
set-option -g display-panes-colour 'white'
set-option -g message-command-style 'default'
set-option -g message-style 'default'
set-option -g clock-mode-colour 'red'
set-option -g clock-mode-style '24'
set-option -g mode-style 'bg=brightred'
set-option -g pane-active-border-style 'fg=brightcyan'
set-option -g pane-border-style 'default'
set-option -g window-status-activity-style 'fg=brightyellow,bg=black'
set-option -g window-status-current-format ' #I:#W#F '
set-option -g window-status-current-style 'fg=black,bg=brightred'
set-option -g window-status-format ' #I:#W#F '
set-option -g window-status-separator ''
## Status
set-option -g status-interval '1'
set-option -g status-justify 'centre'
set-option -g status-style 'fg=brightcyan,bg=black'
set-option -g status-left '#{?client_prefix,#[bg=brightred]#[fg=black]+#[bg=black] , }#[bg=black]#[fg=brightgreen]#S #[fg=brightyellow]#I #[fg=brightcyan]#P'
set-option -g status-left-length '40'
set-option -g status-left-style 'fg=green,bg=black'
set-option -g status-right '#{tmux_mode_indicator} #[fg=brightcyan]#H #[fg=brightyellow]%H:%M:%S'
set-option -g status-right-length '40'
set-option -g status-right-style 'fg=brightcyan,bg=black'
## Terminal capabilities and update environment
set-option -g terminal-overrides '*256color:Tc,xterm*:XT:Cc=\033]12;%p1%s\007:Cr=\033]112\007:Cs=\033[%p1%d q,rxvt-unicode*:XT:sitm@:ritm@'
set-option -g update-environment "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP"
set-environment -gu DBUS_SESSION_BUS_ADDRESS
## }}}
#! {{{ Bindings
## Prefix
set-option -g prefix C-s
unbind-key C-b
bind-key C-s send-prefix
bind-key C-s last-window
## Prompt
unbind-key \;
bind-key \; command-prompt
## Window
bind-key | split-window -h
bind-key - split-window -v
unbind-key '"'
unbind-key %
bind-key C-c new-window
bind-key ` select-window -t 0
bind-key -r C-p select-window -t :- # equiv: previous-window
bind-key -r C-n select-window -t :+ # equiv: next-window
## Pane
bind-key h select-pane -L
bind-key j select-pane -D
bind-key k select-pane -U
bind-key l select-pane -R
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 -U 5
bind-key -r C-l resize-pane -R 5
bind-key _ resize-pane -Z
bind-key H join-pane -b -h -t !
bind-key J join-pane -t !
bind-key @ join-pane -t !
bind-key K kill-pane
bind-key -r "<" swap-window -d -t -1
bind-key -r ">" swap-window -d -t +1
## Copy mode
bind-key Escape copy-mode
unbind-key p
bind-key p paste-buffer
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-selection
bind-key -T copy-mode-vi 'Space' send -X halfpage-down
bind-key -T copy-mode-vi 'Bspace' send -X halfpage-up
# bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xsel -i -p && xsel -o -p | xsel -i -b"
# bind p run "xsel -o | tmux load-buffer - ; tmux paste-buffer"
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -i -sel clip > /dev/null"
bind-key p run "xclip -o -sel clip | tmux load-buffer - ; tmux paste-buffer"
## Miscellaneous
bind-key C attach-session -t . -c '#{pane_current_path}' \; display-message "Session directory set to #{pane_current_path}"
bind-key E set-option mouse \; display-message "Mouse #{?mouse,on,off}"
bind-key X set-window-option synchronize-panes\; display-message "synchronize-panes is now #{?pane_synchronized,on,off}"
bind-key u capture-pane \; save-buffer /tmp/tmux-buffer \; new-window -n "urlview" '$SHELL -c "urlview < /tmp/tmux-buffer"'
bind-key R run-shell '\
: "${XDG_CONFIG_HOME:=$HOME/.config}"; \
if test -f "$XDG_CONFIG_HOME/tmux/tmux.conf"; then \
tmux source "$XDG_CONFIG_HOME/tmux/tmux.conf"; \
tmux display-message "Reloaded configuration: $XDG_CONFIG_HOME/tmux/tmux.conf"; \
elif test -f "$HOME/.tmux/tmux.conf"; then \
tmux source "$HOME/.tmux/tmux.conf"; \
tmux display-message "Reloaded configuration: $HOME/.tmux/tmux.conf"; \
elif test -f "$HOME/.tmux.conf"; then \
tmux source "$HOME/.tmux.conf"; \
tmux display-message "Reloaded configuration: $HOME/.tmux.conf"; \
fi'
## }}}
#! {{{ Plugins
## 'tmux-plugins/tmux-resurrect'
set -g @resurrect-capture-pane-contents 'on'
set -g @resurrect-save 'M-S'
set -g @resurrect-restore 'M-R'
## 'tmux-plugins/tmux-continuum', dep tmux-resurrect
set -g @continuum-restore 'on'
## 'MunifTanjim/tmux-suspend'
set -g @suspend_key 'F12'
## }}}
#! {{{ End
if-shell 'test -f "$HOME/.tmux.conf.local"' 'source "$HOME/.tmux.conf.local"'
run-shell 'command -v tmux-sorcerer >/dev/null && tmux-sorcerer ~/.config/tmux/plugins ~/src/tmux/plugins'
## }}}
## vim:set foldmethod=expr foldexpr=getline(v\:lnum)=~'^#!'?'>1'\:'=':