1
0
mirror of https://github.com/samoshkin/tmux-config.git synced 2026-01-03 00:08:01 +00:00
Files
tmux-config/tmux/tmux.conf

265 lines
8.9 KiB
Bash

# ==========================
# === General settings ===
# ==========================
set -g history-limit 20000
set -g buffer-limit 20
set -sg escape-time 1
set -g display-time 2000
set -g allow-rename off
set -g default-terminal "screen"
set -g remain-on-exit off
# aggressive-resize [on | off]
# alternate-screen [on | off]
# Change prefix key to C-a, easier to type, same to "screen"
unbind C-b
set -g prefix C-a
# Set parent terminal title to reflect current window in tmux session
set -g set-titles on
set -g set-titles-string "#I:#W"
# Start index of window/pane with 1, because we're humans, not computers
set -g base-index 1
setw -g pane-base-index 1
# Enable mouse support
set -g mouse on
# ==========================
# === Key bindings ===
# ==========================
# Reload tmux configuration
bind C-r source-file ~/.tmux.conf \; display "Reloaded"
# Rename session and window
unbind "\$"
unbind ,
bind r command-prompt -I "#{window_name}" "rename-window '%%'"
bind R command-prompt -I "#{session_name}" "rename-session '%%'"
# Split panes
unbind %
unbind '"'
bind | split-window -h
bind _ split-window -v
# Select windows
unbind }
unbind {
unbind "'"
unbind n
unbind p
unbind l
unbind M-n
unbind M-p
bind -r < previous-window
bind -r > next-window
bind -r M-< previous-window -a # prev window with alert
bind -r M-> next-window -a # next window with alert
bind -r Tab last-window # cycle thru MRU tabs
bind W command-prompt -p "go to window #" "select-window -t ':%%'"
# Link window
bind L command-prompt -p "Link window from (session:window): " "link-window -s %% -a"
# Swap panes back and forth with 1st pane
# When in main-(horizontal|vertical) layouts, the biggest/widest panel is always @1
bind \ if '[ #{pane_index} -eq 1 ]' \
'swap-pane -s "!"' \
'select-pane -t:.1 ; swap-pane -d -t 1 -s "!"'
# select/swap panes (counter)clockwise
bind -r o select-pane -t :.+
bind -r O select-pane -t :.-
bind -r C-o swap-pane -D
# Kill pane/window/session shortcuts
unbind &
bind x kill-pane
bind C-x confirm-before -p "kill-window #W? (y/n)" kill-window
bind X confirm-before -p "kill-session #S? (y/n)" kill-session
# Merge session with another one (e.g. move all windows)
# If you use adhoc 1-window sessions, and you want to preserve session upon exit
# but don't want to create a lot of small unnamed 1-window sessions around
# move all windows from current session to main named one (dev, work, etc)
bind C-u command-prompt -p "Session to merge with: " \
"run-shell 'yes | head -n #{session_windows} | xargs -I {} -n 1 tmux movew -t %%'"
# Detach from session
bind d detach
bind D if -F '#{session_many_attached}' \
'confirm-before -p "Detach other clients? (y/n)" "detach -a"' \
'display "Session has only 1 client attached"'
# ==================================================
# === Window monitoring for activity and silence ===
# ==================================================
bind m setw monitor-activity \; display-message 'Monitor window activity [#{?monitor-activity,ON,OFF}]'
bind M if -F '#{monitor-silence}' \
'setw monitor-silence 0 ; display-message "Monitor window silence [OFF]"' \
'command-prompt -p "Monitor silence: interval (s)" "setw monitor-silence %%"'
# Activity bell and whistles
set -g visual-activity on
# TODO: Does not work as well, check on newer versions
# set -g visual-silence on
# BUG: bell-action other ignored · Issue #1027 · tmux/tmux · GitHub - https://github.com/tmux/tmux/issues/1027
# set -g visual-bell on
# setw -g bell-action other
# ================================
# === Copy and scroll ===
# ================================
unbind "#" # list-buffer
unbind = # choose-buffer
unbind ] # paste-buffer
# Prefer vi style key table
setw -g mode-keys vi
# trigger copy mode by pressing PageUp key w/o prepending it with prefix key
bind -n PageUp copy-mode
bind Escape copy-mode
bind p paste-buffer
bind C-p choose-buffer
# Scroll up/down by 1 line, half screen, whole screen
bind -T copy-mode-vi M-Up send-keys -X scroll-up
bind -T copy-mode-vi M-Down send-keys -X scroll-down
bind -T copy-mode-vi M-PageUp send-keys -X halfpage-up
bind -T copy-mode-vi M-PageDown send-keys -X halfpage-down
bind -T copy-mode-vi PageDown send-keys -X page-down
bind -T copy-mode-vi PageUp send-keys -X page-up
# When scrolling with mouse wheel, reduce number of scrolled rows per tick to "2" (default is 5)
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
# Do not copy selection and cancel copy mode on drag end event
# More iTerm style selection: select, then need to mouse click to copy to buffer
unbind -T copy-mode-vi MouseDragEnd1Pane
bind -T copy-mode-vi MouseDown1Pane select-pane \; send-keys -X copy-selection
# =====================================
# === Appearence and status bar ===
# ======================================
# Load theme
source ~/.tmux/theme.conf
set -g mode-style "fg=default,bg=$color_main"
# command line style
set -g message-style "fg=$color_main,bg=$color_dark"
# status line style
set -g status-style "fg=$color_status_text,bg=$color_dark"
# window segments in status line
set -g window-status-separator ""
separator_powerline_left=""
separator_powerline_right=""
setw -g window-status-style "fg=$color_status_text,bg=$color_dark"
setw -g window-status-format " #I:#W "
setw -g window-status-current-style "fg=$color_light,bold,bg=$color_main"
setw -g window-status-current-format "#[fg=$color_dark,bg=$color_main]$separator_powerline_right#[default] #I:#W# #[fg=$color_main,bg=$color_dark]$separator_powerline_right#[default]"
# when window has monitoring notification
setw -g window-status-activity-style "fg=$color_main,bg=$color_dark"
# outline for active pane
setw -g pane-active-border-style "fg=$color_main"
# general status bar settings
set -g status on
set -g status-interval 5
set -g status-position top
set -g status-justify left
set -g status-right-length 140
# define widgets we're going to use in status bar
# note, that this is not the complete list, some of them are loaded from plugins
wg_session="#[fg=$color_session_text] #S #[default]"
wg_battery="#{battery_status_fg} #{battery_icon} #{battery_percentage}"
wg_date="#[fg=$color_secondary]%h %d %H:%M#[default]"
wg_host="#[fg=$color_secondary]#(echo $USER)#[default]@#H"
wg_is_zoomed="#[fg=$color_dark,bg=$color_secondary]#{?window_zoomed_flag,[Z],}#[default]"
set -g status-left "$wg_session"
set -g status-right "#{prefix_highlight} $wg_is_zoomed #{sysstat_cpu} | #{sysstat_mem} | #{sysstat_loadavg} | $wg_host | $wg_date $wg_battery #{online_status}"
# online and offline icon for tmux-online-status
set -g @online_icon "#[fg=$color_level_good]●#[default]"
set -g @offline_icon "#[fg=$color_level_achtung]●#[default]"
# Configure view templates for tmux-plugin-sysstat "MEM" and "CPU" widget
set -g @sysstat_mem_size_unit "G"
set -g @sysstat_mem_view_tmpl '#[fg=#{mem.color}]MEM:#{mem.pused}#[default] (#{mem.used})'
set -g @sysstat_cpu_view_tmpl '#[fg=#{cpu.color}]CPU:#{cpu.pused}#[default]'
# Configure colors for tmux-plugin-sysstat "MEM" and "CPU" widget
set -g @sysstat_cpu_color_low "$color_level_good"
set -g @sysstat_cpu_color_medium "$color_level_warn"
set -g @sysstat_cpu_color_high "$color_level_achtung"
set -g @sysstat_mem_color_ok "$color_level_good"
set -g @sysstat_mem_color_stress "$color_level_achtung"
# Configure tmux-battery widget colors
set -g @batt_color_full_charge "#[fg=$color_level_good]"
set -g @batt_color_high_charge "#[fg=$color_level_good]"
set -g @batt_color_medium_charge "#[fg=$color_level_warn]"
set -g @batt_color_low_charge "#[fg=$color_level_achtung]"
# Configure tmux-prefix-highlight colors
set -g @prefix_highlight_output_prefix '['
set -g @prefix_highlight_output_suffix ']'
set -g @prefix_highlight_fg "$color_dark"
set -g @prefix_highlight_bg "$color_secondary"
set -g @prefix_highlight_show_copy_mode 'on'
set -g @prefix_highlight_copy_mode_attr "fg=$color_dark,bg=$color_secondary"
# ============================
# === Hooks ===
# ============================
# Prompt to rename window right after it's created
set-hook -g after-new-window 'command-prompt -I "#{window_name}" "rename-window '%%'"'
# ============================
# === Plugins ===
# ============================
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-battery'
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
set -g @plugin 'tmux-plugins/tmux-online-status'
set -g @plugin 'tmux-plugins/tmux-sidebar'
set -g @plugin 'tmux-plugins/tmux-copycat'
set -g @plugin 'tmux-plugins/tmux-open'
set -g @plugin 'samoshkin/tmux-plugin-sysstat'
# Plugin properties
set -g @sidebar-tree 't'
set -g @sidebar-tree-focus 'T'
set -g @sidebar-tree-command 'tree -C'
set -g @open-S 'https://www.google.com/search?q='
# Run all plugins' scripts
run '~/.tmux/plugins/tpm/tpm'