literate-dotfiles/tmux.org
Thomas Dehaeze 3e97711adc Change indentation of all blocks.
Use (setq org-src-preserve-indentation t) for Emacs.
2021-01-08 01:26:27 +01:00

8.5 KiB

Tmux Configuration

Line

# Activate the status bar
set -g status "on"

# default statusbar color
set-option -g status-style bg=colour237,fg=colour223 # bg=bg1, fg=fg1

# default window title colors
set-window-option -g window-status-style bg=colour214,fg=colour237 # bg=yellow, fg=bg1

# default window with an activity alert
set-window-option -g window-status-activity-style bg=colour237,fg=colour248 # bg=bg1, fg=fg3

# active window title colors
set-window-option -g window-status-current-style bg=red,fg=colour237 # fg=bg1

# pane border
set-option -g pane-active-border-style fg=colour250 #fg2
set-option -g pane-border-style fg=colour237 #bg1

# message infos
set-option -g message-style bg=colour239,fg=colour223 # bg=bg2, fg=fg1

# writing commands inactive
set-option -g message-command-style bg=colour239,fg=colour223 # bg=fg3, fg=bg1

# pane number display
set-option -g display-panes-active-colour colour250 #fg2
set-option -g display-panes-colour colour237 #bg1

# clock
set-window-option -g clock-mode-colour colour109 #blue

# bell
set-window-option -g window-status-bell-style bg=colour167,fg=colour235 # bg=red, fg=bg

## Theme settings mixed with colors (unfortunately, but there is no cleaner way)
set-option -g status-justify "left"
set-option -g status-left-style none
set-option -g status-left-length "80"
set-option -g status-right-style none
set-option -g status-right-length "80"
set-window-option -g window-status-separator ""

set-option -g status-left "#[fg=colour248, bg=colour241] #S #[fg=colour241, bg=colour237, nobold, noitalics, nounderscore]"
set-option -g status-right "#[fg=colour239, bg=colour237, nobold, nounderscore, noitalics]#[fg=colour246,bg=colour239] %Y-%m-%d  %H:%M #[fg=colour248, bg=colour239, nobold, noitalics, nounderscore]#{?client_prefix,#[fg=colour124],}#[fg=colour237, bg=colour248]#{?client_prefix,#[bg=colour124],} #h "

set-window-option -g window-status-current-format "#[fg=colour237, bg=colour214, nobold, noitalics, nounderscore]#[fg=colour239, bg=colour214] #I #[fg=colour239, bg=colour214, bold] #W #[fg=colour214, bg=colour237, nobold, noitalics, nounderscore]"
set-window-option -g window-status-format "#[fg=colour237,bg=colour239,noitalics]#[fg=colour223,bg=colour239] #I #[fg=colour223, bg=colour239] #W #[fg=colour239, bg=colour237, noitalics]"

Bindings

# Set prefix to 'C-Space'
unbind C-b
set -g prefix C-Space

# Reload the config using 'C-Space + r'
bind r source-file ~/.tmux.conf \; display-message "Config reloaded..."

# Simulate 'C-l' to clear the terminal
bind C-l send-keys C-l \; clear-history

# Open new panes with the path of the current pane.
unbind c
bind c new-window -c '#{pane_current_path}'

# Vim-like key bindings for pane navigation (default uses cursor keys).
unbind h
bind h select-pane -L
unbind j
bind j select-pane -D
unbind k
bind k select-pane -U
unbind l # normally used for last-window
bind l select-pane -R

# Move Panes
unbind L
bind L swap-pane -D
unbind H
bind H swap-pane -U

# Resizing (mouse also works).
unbind Left
bind -r Left resize-pane -L 5
unbind Right
bind -r Right resize-pane -R 5
unbind Down
bind -r Down resize-pane -D 5
unbind Up
bind -r Up resize-pane -U 5

# Fast toggle (normally prefix-l).
bind ^space last-window

# Intuitive window-splitting keys.
bind / split-window -h -c '#{pane_current_path}' # normally prefix-%
bind - split-window -v -c '#{pane_current_path}' # normally prefix-"

# Swap windows
bind-key -r "<" swap-window -t -1
bind-key -r ">" swap-window -t +1

# Smart pane switching with awareness of Vim splits
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-h if-shell "$is_vim" "send-keys C-h"  "select-pane -L"
bind-key -n C-j if-shell "$is_vim" "send-keys C-j"  "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k"  "select-pane -U"
bind-key -n C-l if-shell "$is_vim" "send-keys C-l"  "select-pane -R"

# Set 'C-Space + v' to enter copy-mode
unbind [
bind-key v copy-mode

# Set 'C-Space + C-v' to paste
unbind ]
bind-key C-v paste-buffer

# Setup 'v' to begin selection as in Vim and 'y' to 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 "xsel -i -p && xsel -o -p | xsel -i -b"
bind-key -T copy-mode-vi 'Escape' send -X cancel
bind-key -T copy-mode-vi 'C-v' send-keys -X rectangle-toggle

Settings

# Activity monitoring
set -g visual-activity off

# Automatically renumber window numbers on closing a pane (tmux >= 1.7).
set -g renumber-windows on

# Mouse can be used to select panes, select windows (by clicking on the status bar), resize panes
set -g mouse on

set -g default-terminal "screen-256color"
set -ga terminal-overrides ',xterm-256color:Tc'

set -g history-limit 262144

# Start window and pane numbering at 1, (0 is too hard to reach)
set -g base-index 1
set -g pane-base-index 1

# Don't wait for an escape sequence after seeing C-a
set -s escape-time 0

# Dynamically update iTerm tab and window titles
set -g set-titles on

# Needed as on tmux 1.9 and up (defaults to off)
set -g focus-events on

# But don't change tmux's own window titles
set-option -g allow-rename off

# Don't wrap searches; it's super confusing given tmux's reverse-ordering of position info in copy mode
set -w -g wrap-search off

# Restore pre-2.1 behavior of scrolling with the scrollwheel in Vim, less, copy mode etc, otherwise entering copy mode if not already in it.
bind-key -T root WheelUpPane \
  if-shell -Ft= '#{?pane_in_mode,1,#{mouse_any_flag}}' \
    'send -Mt=' \
    'if-shell -Ft= "#{alternate_on}" "send -t= Up" "copy-mode -et="'
bind-key -T root WheelDownPane \
  if-shell -Ft = '#{?pane_in_mode,1,#{mouse_any_flag}}' \
    'send -Mt=' \
    'if-shell -Ft= "#{alternate_on}"  "send -t= Down" "send -Mt="'

# Stay in copy mode on drag end, but otherwise exit for mouse up.
# Requires patch from https://github.com/tmux/tmux/issues/326
# unbind-key -t vi-copy MouseDragEnd1Pane
# bind-key -t vi-copy MouseUp1Pane cancel

bind-key -n MouseDrag1Status swap-window -t=
# bind-key -n MouseDown3Status new-window -a -t=

bind-key -n MouseDrag1Status swap-window -t=
# bind-key -n MouseDown3Status new-window -a -t=


# #T      = standard window title (last command, see ~/.bash_profile)
# #h      = short hostname
# #S      = session name
# #W      = tmux window name
set -g set-titles-string "#T : #h > #S > #W"

# Show bells in window titles
set -g window-status-bell-style fg=yellow,bold,underscore

# Causes tmux to resize a window based on the smallest client actually viewing it, not on the smallest one attached to the entire session
set-window-option -g aggressive-resize

Plugins

Install plugins

set -g @plugin 'tmux-plugins/tpm'
# set -g @plugin 'tmux-plugins/tmux-sessionist'
# set -g @plugin 'tmux-plugins/tmux-resurrect'
# set -g @plugin 'tmux-plugins/tmux-continuum'
# set -g @plugin 'tmux-plugins/tmux-battery'
set -g @plugin 'nhdaly/tmux-better-mouse-mode'
set -g @plugin 'seebi/tmux-colors-solarized'

Configuration

# =============================================================
# tmux-resurrect
# =============================================================
# for vim
set -g @resurrect-strategy-vim 'session'
# for neovim
set -g @resurrect-strategy-nvim 'session'

# Restoring pane contents
set -g @resurrect-capture-pane-contents 'on'

run-shell ~/.tmux/plugins/tmux-resurrect/resurrect.tmux
# =============================================================


# =============================================================
# tmux-continuum
# =============================================================
set -g @continuum-boot 'on'
set -g @continuum-boot-options 'iterm,fullscreen'
set -g @continuum-save-interval '15'

run-shell ~/.tmux/plugins/tmux-continuum/continuum.tmux
# =============================================================


# =============================================================
# tmux-battery
# =============================================================
set -g @batt_charged_icon "="
set -g @batt_charging_icon "+"
set -g @batt_discharging_icon "-"
set -g @batt_attached_icon "o"
# =============================================================

Colors

set -g @colors-solarized 'light'

Initialize TMUX plugin manager

run '~/.tmux/plugins/tpm/tpm'