Skip to content

Instantly share code, notes, and snippets.

@swtornio
Last active August 6, 2022 03:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save swtornio/09178f455cd095b8974d6f59a7da539c to your computer and use it in GitHub Desktop.
Save swtornio/09178f455cd095b8974d6f59a7da539c to your computer and use it in GitHub Desktop.
tmux config
#############################################
## DEFAULT GENERAL SETTINGS (tmux show -g) ##
#############################################
set-option -g activity-action other
set-option -g assume-paste-time 1
set-option -g base-index 0
set-option -g bell-action any
set-option -g default-command ""
set-option -g default-shell "/bin/bash"
set-option -g destroy-unattached off
set-option -g detach-on-destroy on
set-option -g display-panes-active-colour red
set-option -g display-panes-colour blue
set-option -g display-panes-time 1000
set-option -g display-time 750
set-option -g history-limit 2000
set-option -g key-table "root"
set-option -g lock-after-time 0
set-option -g lock-command "lock -np"
set-option -g message-command-style fg=yellow,bg=black
set-option -g message-style fg=black,bg=yellow
set-option -g mouse off
set-option -g prefix C-b
set-option -g prefix2 None
set-option -g renumber-windows off
set-option -g repeat-time 500
set-option -g set-titles off
set-option -g set-titles-string "#S:#I:#W - \"#T\" #{session_alerts}"
set-option -g silence-action other
set-option -g status on
set-option -g status-interval 15
set-option -g status-justify left
set-option -g status-keys emacs
set-option -g status-left "[#S] "
set-option -g status-left-length 10
set-option -g status-left-style default
set-option -g status-position bottom
set-option -g status-right " \"#{=21:pane_title}\" %H:%M %d-%b-%y"
set-option -g status-right-length 40
set-option -g status-right-style default
set-option -g status-style fg=black,bg=green
set-option -g update-environment[0] "DISPLAY"
set-option -g update-environment[1] "SSH_ASKPASS"
set-option -g update-environment[2] "SSH_AUTH_SOCK"
set-option -g update-environment[3] "SSH_AGENT_PID"
set-option -g update-environment[4] "SSH_CONNECTION"
set-option -g update-environment[5] "WINDOWID"
set-option -g update-environment[6] "XAUTHORITY"
set-option -g visual-activity off
set-option -g visual-bell off
set-option -g visual-silence off
set-option -g word-separators " -_@"
##########################
## DEFAULT COLOR SCHEME ##
##########################
set-option -g clock-mode-colour blue
set-option -g clock-mode-style 24
set-option -g mode-bg yellow
set-option -g mode-fg black
set-option -g pane-active-border-bg default
set-option -g pane-active-border-fg green
set-option -g pane-border-bg default
set-option -g pane-border-fg white
set-option -g window-status-activity-bg green
set-option -g window-status-activity-fg black
set-option -g window-status-current-bg green
set-option -g window-status-current-fg black
set-option -g window-status-current-format "#I:#W#F"
set-option -g window-status-format "#I:#W#F"
#############################
## CUSTOM GENERAL SETTINGS ##
#############################
set -g base-index 0 # Start window numbers at 0
set -g history-limit 50000 # Increase size of scrollback buffer
# Log all panes by default to $HOME/tmux_logs
run-shell -b 'if [ ! -d "$HOME/tmux_logs" ];then mkdir $HOME/tmux_logs; fi'
#############################
## ADDITIONAL KEY BINDINGS ##
#############################
# Prefix + a: Enable activity monitoring for window
bind a setw monitor-activity on\; display 'Activity Monitor: Enabled'
# Prefix + A: Disable activity monitoring for window
bind A setw monitor-activity off\; display 'Activity Monitor: Disabled'
# Prefix + B (Shift-b): Toggle use of mouse for navigation
bind B set -g mouse\; display "Mouse Mode toggled"
# Prefix + c: Enable logging by default when a new window is created
bind c new-window\; pipe-pane -o 'bash -c "while IFS= read -r line; do echo \"\$(date +%%Y%%m%%dT%%H%%M%%SZ%%z): \$line\"; done" >>$HOME/tmux_logs/"'%Y-%m-%d-%H:%M:%S'-win#I-pane#P-#W-#S-tmux.log"'
# Prefix + C (Shift-c): Enable better copy mode
# Usage:
# Scroll mouse wheel or click and drag on text to enter copy mode
# Click and drag to select text (use page up and down for large amounts)
# Use Alt-c to copy into tmux buffer and OS buffer
# Click mouse wheel to copy into tmux buffer and OS buffer and exit copy mode
# Use Alt-v or click the mouse wheel to paste from tmux buffer
# Use Shift-Ctrl-c to copy only into OS buffer
# Use Shift-mouse wheel to paste from OS buffer
# ESC or right click to exit copy mode (better copy mode will still be enabled)
# Prefix + Z to disable
bind C \
set -g mouse on\;\
set -g set-clipboard off\;\
unbind -T copy-mode MouseDragEnd1Pane\;\
unbind -T copy-mode-vi MouseDragEnd1Pane\;\
bind -T copy-mode MouseDown1Pane send-keys -X clear-selection\;\
bind -T copy-mode-vi MouseDown1Pane send-keys -X clear-selection\;\
bind -T copy-mode MouseDown3Pane send-keys -X cancel\;\
bind -T copy-mode-vi MouseDown3Pane send-keys -X cancel\;\
bind -T copy-mode MouseDown2Pane send-keys -X copy-pipe-and-cancel "xclip -i -sel p -f | xclip -i -sel c"\;\
bind -T copy-mode-vi MouseDown2Pane send-keys -X copy-pipe-and-cancel "xclip -i -sel p -f | xclip -i -sel c"\;\
bind -n MouseDown2Pane paste-buffer\;\
bind -T copy-mode M-c send-keys -X copy-pipe "xclip -i -sel p -f | xclip -i -sel c"\;\
bind -T copy-mode-vi M-c send-keys -X copy-pipe "xclip -i -sel p -f | xclip -i -sel c"\;\
bind -n M-v paste-buffer\;\
display 'Copy Mode Plus: Enabled'
# Prefix + e: Enable silence monitoring for window
bind e command-prompt -p 'Monitor silence for how long (seconds)?:' "setw monitor-silence %%"
# Prefix + E: Disable silence monitoring for window
bind E setw monitor-silence 0\; display 'Silence Monitoring: Disabled'
# Prefix + h: Split window horizontally
#bind h split-window -v
bind h split-window -v\; pipe-pane -o 'bash -c "while IFS= read -r line; do echo \"\$(date +%%Y%%m%%dT%%H%%M%%SZ%%z): \$line\"; done" >>$HOME/tmux_logs/"'%Y-%m-%d-%H:%M:%S'-win#I-pane#P-#W-#S-tmux.log"'
# Prefix + H (Shift-h): Save pane history to log file
bind H command-prompt -p "Save history to filename: ,Lines to save (up to #{history_limit}): " -I "~/tmux_logs/%Y-%m-%d-%H:%M:%S-win#I-pane#P-#W-#S-tmux.log,#{history_limit}" 'capture-pane -J -S -%2; save-buffer %1 ; delete-buffer'
# Prefix + Q (Shift-q): kill window
bind Q confirm-before -p "kill-window #W? (y/n)" kill-window
# Prefix + R (Shift-r): Reload tmux with changes to .tmux.conf
bind R source-file ~/.tmux.conf \; display '~/.tmux.conf sourced'
# Prefix + S (Shift-s): Save logs of all output to pane
bind S pipe-pane 'bash -c "while IFS= read -r line; do echo \"\$(date +%%Y%%m%%dT%%H%%M%%SZ%%z): \$line\"; done" >>$HOME/tmux_logs/"'%Y-%m-%d-%H:%M:%S'-win#I-pane#P-#W-#S-tmux.log"'\; display "Logging enabled"
# Prefix + v: Split window vertically
bind v split-window -h
# Prefix + X (Shift-x): Stop logging of all output in pane
bind X send-keys "kill $(pgrep -f "win$({tmux,display,-p,'#I'})-pane$({tmux,display,-p,'#P'})-.*-$({tmux,display,-p,'#S'})-tmux.log") >/dev/null 2>&1" Enter\; pipe-pane -o\; display "Logging disabled"
# Prefix + Z (Shift-z): Disable better copy mode (see Prefix + C above)
bind Z \
set -g mouse off\;\
set -g set-clipboard external\;\
unbind -T copy-mode MouseDown1Pane\;\
unbind -T copy-mode MouseDown2Pane\;\
unbind -T copy-mode MouseDown3Pane\;\
unbind -T copy-mode-vi MouseDown1Pane\;\
unbind -T copy-mode-vi MouseDown2Pane\;\
unbind -T copy-mode-vi MouseDown3Pane\;\
unbind -n MouseDown2Pane\;\
unbind -T copy-mode M-c\;\
unbind -T copy-mode-vi M-c\;\
unbind -n M-v\;\
bind -T copy-mode MouseDragEnd1Pane send-keys -X copy-selection-and-cancel\;\
bind -T copy-mode MouseDown1Pane select-pane\;\
bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-selection-and-cancel\;\
bind -T copy-mode-vi MouseDown1Pane select-pane\;\
display 'Copy Mode Plus: Disabled'
# Prefix + Ctrl-[p/n]: Navigate to previous/next window
bind C-p previous-window
bind C-n next-window
# Prefix + Ctrl-[Left/Right]: Navigate to previous/next window
bind C-Left previous-window
bind C-Right next-window
# Prefix + | (Shift-\): Split window vertically
#bind | split-window -h
bind | split-window -h\; pipe-pane -o 'bash -c "while IFS= read -r line; do echo \"\$(date +%%Y%%m%%dT%%H%%M%%SZ%%z): \$line\"; done" >>$HOME/tmux_logs/"'%Y-%m-%d-%H:%M:%S'-win#I-pane#P-#W-#S-tmux.log"'
# Prefix + _ (Shift--): Split window horizontally
#bind _ split-window -v
bind _ split-window -v\; pipe-pane -o 'bash -c "while IFS= read -r line; do echo \"\$(date +%%Y%%m%%dT%%H%%M%%SZ%%z): \$line\"; done" >>$HOME/tmux_logs/"'%Y-%m-%d-%H:%M:%S'-win#I-pane#P-#W-#S-tmux.log"'
###############################
## STATUS BAR CUSTOMIZATIONS ##
###############################
# Highlight when prefix active or in copy mode
set -g status-right '#{?client_prefix, Prefix,}#{?pane_in_mode, Copy,} |"#{=21:pane_title}" %H:%M %d-%b-%y'
# Set gray powerline status bar with user-defined color scheme
bind > command-prompt -p 'Set terminal color theme to (e.g. red or cyan or colour129):' \
'set -g status-interval 1; set -g status-fg %1; set -g status-bg colour233; set -g status-left-bg colour233; set -g status-left-fg colour243; set -g status-left-length 40; set -g status-left "#[fg=colour233,bg=%1,bold] #S #[fg=%1,bg=colour240,nobold]#[fg=colour233,bg=colour240] #(whoami) #[fg=colour240,bg=colour235]#[fg=colour240,bg=colour235] #I:#P #[fg=colour235,bg=colour233,nobold]"; set -g status-right-bg colour233; set -g status-right-fg colour243; set -g status-right-length 150; set -g status-right "#{?client_prefix,#[fg=%1]#[bg=colour233]#[bold] Prefix,#[fg=colour233]#[bg=colour233]}#{?pane_in_mode,#[fg=%1]#[bg=colour233]#[bold] Copy,#[fg=colour254]#[bg=colour234]}#[nobold]#[fg=colour235,bg=colour233] #[fg=colour240,bg=colour235] %H:%M:%S #[fg=colour240,bg=colour235]#[fg=colour233,bg=colour240] %d-%b-%y #[fg=%1,bg=colour240]#[fg=colour233,bg=%1,bold] #H "; set -g window-status-format " #I:#W#F "; set -g window-status-current-format "#[fg=colour233,bg=black]#[fg=%1,nobold] #I:#W#F #[fg=colour233,bg=black,nobold]"; set -g window-status-current-bg %1; set -g window-status-current-fg colour235; set -g window-status-activity-bg colour245; set -g window-status-activity-fg colour233; set -g window-status-separator " "; set -g pane-border-bg default; set -g pane-border-fg colour238; set -g pane-active-border-bg default; set -g pane-active-border-fg %1; set -g display-panes-colour colour233; set -g display-panes-active-colour colour245; set -g clock-mode-colour %1; set -g clock-mode-style 24; set -g message-bg %1; set -g message-fg black; set -g message-command-bg colour233; set -g message-command-fg black; set -g mode-bg %1; set -g mode-fg colour232'
# Back to default color theme
bind < \
set -g status-interval 15\;\
set -g status-bg green\;\
set -g status-fg black\;\
set -g status-left-bg green\;\
set -g status-left-fg black\;\
set -g status-left-length 10\;\
set -g status-left "[#S] "\;\
set -g status-right-bg green\;\
set -g status-right-fg black\;\
set -g status-right-length 40\;\
set -g status-right '#{?client_prefix, Prefix,}#{?pane_in_mode, Copy,} |"#{=21:pane_title}" %H:%M %d-%b-%y'\;\
set -g window-status-format "#I:#W#F"\;\
set -g window-status-current-format "#I:#W#F"\;\
set -g window-status-current-bg green\;\
set -g window-status-current-fg black\;\
set -g window-status-activity-bg green\;\
set -g window-status-activity-fg black\;\
set -g window-status-separator " "\;\
set -g status-justify left\;\
set -g pane-border-bg default\;\
set -g pane-border-fg white\;\
set -g pane-active-border-bg default\;\
set -g pane-active-border-fg green\;\
set -g display-panes-colour blue\;\
set -g display-panes-active-colour red\;\
set -g clock-mode-colour blue\;\
set -g clock-mode-style 24\;\
set -g message-bg yellow\;\
set -g message-fg black\;\
set -g message-command-bg green\;\
set -g message-command-fg black\;\
set -g mode-bg yellow\;\
set -g mode-fg black
#############
## PLUGINS ##
#############
# Tmux plugin manager (https://github.com/tmux-plugins/tpm)
#set -g @plugin 'tmux-plugins/tpm'
# Show directory tree in sidebar (https://github.com/tmux-plugins/tmux-sidebar)
#set -g @plugin 'tmux-plugins/tmux-sidebar'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
#run '~/.tmux/plugins/tpm/tpm'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment