Skip to content

Instantly share code, notes, and snippets.

@bartman
Last active December 27, 2021 16:24
Show Gist options
  • Save bartman/1eed0693b34834381942 to your computer and use it in GitHub Desktop.
Save bartman/1eed0693b34834381942 to your computer and use it in GitHub Desktop.
tmux

This gist has my tmux config.

You can find it here: https://gist.github.com/bartman/1eed0693b34834381942

The files need to be placed in following tree structure:

    ~/
    ├── .tmux.conf
    └── .tmux/
        ├── current-path-1.9+.conf
        ├── mode-mouse-1.9-2.0.conf
        ├── mode-mouse-2.1.conf
        ├── style-after-2.9.conf
        ├── style-before-2.9.conf
        ├── vi-copy-mode-2.6.conf
        ├── vi-copy-mode-pre-2.6.conf
        └── scripts/
            ├── fit.conf
            └── fit.sh
# tmux.conf
# https://github.com/edkolev/dots/blob/master/tmux.conf
# Updates for tmux 1.9's current pane splitting paths.
unbind-key c ; bind-key c new-window -c '#{pane_current_path}'
unbind-key '"' ; bind-key '"' split-window -v -c '#{pane_current_path}'
unbind-key % ; bind-key % split-window -h -c '#{pane_current_path}'
# tmux :fit script
bind-key F run-shell ~/.tmux/scripts/fit.sh
#!/bin/bash
# some useful variables, example value, and description
# client_tty - /dev/pts/0 - this identifies the client running the script
# session_name - 0 - which session client is connected to
# window_index - 1 - which window the session has visible
# pane_index - 1 - which pane the session has focused
client=$( tmux display-message -p '#{client_tty}' )
#session=$( tmux display-message -t "$client" -p '#{session_name}' )
window=$( tmux display-message -t "$client" -p '#{window_index}' )
#pane=$( tmux display-message -p '#{pane_index}' )
#echo "# I am client=$client session=$session window=$window"
success=""
failed=""
for c in $( tmux list-clients -F '#{client_tty}' ) ; do
if [[ "$client" = "$c" ]] ; then
# skip client running this script
continue
fi
w=$( tmux display-message -t "$c" -p '#{window_index}' )
#echo >&2 "# client=$c window=$w"
if [ "$window" = "$w" ] ; then
#echo >&2 "# tmux detach-client -t $c"
if tmux detach-client -t "$c" ; then
success="${success} $c"
else
failed="${failed} $c"
fi
fi
done
if [ -n "${success}" ] ; then
msg="Disconnected clients $success"
[ -n "${failed}" ] && msg="$msg, but failed to disconnect $failed"
elif [ -n "${failed}" ] ; then
msg="Failed to disconnect clients $failed"
else
msg="This is the only client viewing window $window"
fi
tmux display-message "$msg"
#tmux.conf
# https://github.com/tangledhelix/dotfiles/blob/master/tmux.conf
set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on
# Toggle mouse on
bind m \
set -g mode-mouse on \;\
set -g mouse-resize-pane on \;\
set -g mouse-select-pane on \;\
set -g mouse-select-window on \;\
display 'Mouse: ON'
# Toggle mouse off
bind M \
set -g mode-mouse off \;\
set -g mouse-resize-pane off \;\
set -g mouse-select-pane off \;\
set -g mouse-select-window off \;\
display 'Mouse: OFF'
#tmux.conf
set -g mouse on
# Toggle mouse on
bind m \
set -g mouse on \;\
display 'Mouse: ON'
# Toggle mouse off
bind M \
set -g mouse off \;\
display 'Mouse: OFF'
# tmux.conf
# https://github.com/seebi/tmux-colors-solarized/blob/master/tmuxcolors-256.conf
set-option -g status-style fg=colour136,bg=colour235 #yellow,base02
# default window title colors
set-window-option -g window-status-style fg=colour244,bg=default,none
# window title colors
set-window-option -g window-status-current-style fg=colour166,bg=default,none
set-window-option -g window-status-last-style fg=colour136,bg=default,none
set-window-option -g window-status-bell-style fg=default,bg=colour52
set-window-option -g window-status-activity-style fg=default,bg=default,underscore
set-window-option -g window-status-format "#I:#W#F"
set-window-option -g window-status-current-format "#I:#W#F"
# pane border
set-option -g pane-border-style fg=colour240 #colour235 #base02
set-option -g pane-active-border-style fg=yellow #colour240 #base01
# message text
set-option -g message-style fg=colour166,bg=colour235 #orange,base02
# pane number display
set-option -g display-panes-active-colour colour33 #blue
set-option -g display-panes-colour colour166 #orange
# clock
set-window-option -g clock-mode-colour green #green
set-window-option -g clock-mode-style 24
# tmux >=2.2: does always use utf8, keep the option older environments
# using tmux <2.2 (i.e. Debian Jessie)
set -gq status-utf8 on
# tmux.conf
# https://github.com/seebi/tmux-colors-solarized/blob/master/tmuxcolors-256.conf
set-option -g status-bg colour235 #base02
set-option -g status-fg colour136 #yellow
set-option -g status-attr default
# default window title colors
set-window-option -g window-status-fg colour244 #base0
set-window-option -g window-status-bg default
set-window-option -g window-status-attr dim
# window title colors
set-window-option -g window-status-current-fg colour166 # orange
set-window-option -g window-status-current-bg default
set-window-option -g window-status-current-attr dim
if-shell "[[ `tmux -V` == *1.[89]* ]]" 'set-window-option -g window-status-last-fg colour136 # dark orange'
if-shell "[[ `tmux -V` == *1.[89]* ]]" 'set-window-option -g window-status-last-bg default'
if-shell "[[ `tmux -V` == *1.[89]* ]]" 'set-window-option -g window-status-last-attr dim'
if-shell "[[ `tmux -V` == *1.9* ]]" 'set-window-option -g window-status-alert-fg default'
if-shell "[[ `tmux -V` == *1.9* ]]" 'set-window-option -g window-status-alert-bg default'
if-shell "[[ `tmux -V` == *1.9* ]]" 'set-window-option -g window-status-alert-attr reverse'
set-window-option -g window-status-bell-fg default
set-window-option -g window-status-bell-bg colour52
set-window-option -g window-status-bell-attr default
set-window-option -g window-status-activity-fg default
set-window-option -g window-status-activity-bg default
set-window-option -g window-status-activity-attr underscore
if-shell "[[ `tmux -V` == *1.9* ]]" 'set-window-option -g window-status-content-fg default'
if-shell "[[ `tmux -V` == *1.9* ]]" 'set-window-option -g window-status-content-bg default'
if-shell "[[ `tmux -V` == *1.9* ]]" 'set-window-option -g window-status-content-attr underscore'
set-window-option -g window-status-format "#I:#W#F"
set-window-option -g window-status-current-format "#I:#W#F"
# pane border
set-option -g pane-border-fg colour240 #colour235 #base02
set-option -g pane-active-border-fg yellow #colour240 #base01
# message text
set-option -g message-bg colour235 #base02
set-option -g message-fg colour166 #orange
# pane number display
set-option -g display-panes-active-colour colour33 #blue
set-option -g display-panes-colour colour166 #orange
# clock
set-window-option -g clock-mode-colour green #green
set-window-option -g clock-mode-style 24
# tmux >=2.2: does always use utf8, keep the option older environments
# using tmux <2.2 (i.e. Debian Jessie)
set -gq status-utf8 on
# color needs to be set early in tmux 1.8 for some reason
set -g default-terminal "screen-256color"
set -g default-shell /bin/zsh
set -g default-command /bin/zsh
# Fix scrolling
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
# set window split
bind-key '"' split-window -v
bind-key % split-window -h
# detach
bind-key C-d detach-client
# Make C-a q kill the pane (simular to GNU screen)
bind-key q confirm-before -p "kill-pane #P? (y/n)" kill-pane
# cycle windows
bind-key C-n next-window
bind-key C-p previous-window
# status bar
set -g status on
set -g status-keys emacs
set -g status-interval 10
set -g status-justify centre
set -g status-left-length 40
set -g status-left "#[fg=brightblack]|#[fg=green]#h#[fg=brightblack]|#[fg=brightblue]#(ip r g 8.8.8.8 | sed -rne 's/ uid.*//' -e 's/.*src //p' | xargs)#[fg=brightblack]|"
set -g status-right-length 30
set -g status-right "#[fg=brightblack]|#[fg=brightblue]#S #I:#P#[fg=brightblack]|#[fg=green]%b/%d#[fg=brightblack]|#[fg=green]%H:%M#[fg=brightblack]|"
# C-b is not acceptable -- Vim uses it
set-option -g prefix C-a
bind-key C-a last-window
# Start numbering at 1
set -g base-index 1
set -g pane-base-index 1
# Allows for faster key repetition
set -s escape-time 0
# Rather than constraining window size to the maximum size of any client
# connected to the *session*, constrain window size to the maximum size of any
# client connected to *that window*. Much more reasonable.
setw -g aggressive-resize on
# Allows us to use C-a a <command> to send commands to a TMUX session inside
# another TMUX session
bind-key a send-prefix
# Activity monitoring
setw -g monitor-activity on
set -g visual-activity on
# hjkl pane traversal
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind C-h select-pane -L
bind C-j select-pane -D
bind C-k select-pane -U
bind C-l select-pane -R
# HJKL pane swapping in that direction
# (NOTE: tmux doesn't support swap -L or -R)
#bind H swap-pane -L
bind J swap-pane -D
bind K swap-pane -U
#bind L swap-pane -R
# resize like in vim
# https://github.com/hatoishi/dotfiles/blob/master/tmux.conf
bind < resize-pane -L 10
bind > resize-pane -R 10
bind - resize-pane -D 10
bind + resize-pane -U 10
# full-screen a pane (toggle)
# http://blog.sanctum.geek.nz/zooming-tmux-panes/
bind z resize-pane -Z
bind-key C command-prompt -p "Name of new window: " "new-window -n '%%'"
# reload config
bind r source-file ~/.tmux.conf \; display-message "Config reloaded..."
# auto window rename
set-window-option -g automatic-rename
# logging toggle
# https://unix.stackexchange.com/questions/5832/is-there-an-equivalent-of-gnu-screens-log-command-in-tmux
#bind-key H pipe-pane -o "exec cat >>$HOME/'#W-tmux.log'" '\;' display-message 'Toggled logging to $HOME/#W-tmux.log'
bind-key H { pipe-pane -o "exec cat >>$HOME/'#W-tmux.log'" ; display-message 'Toggled logging to $HOME/#W-tmux.log' }
# ------------------------------------------------------------------------
# https://github.com/neovim/neovim/issues/2093
set -g escape-time 20
# ------------------------------------------------------------------------
if-shell "tmux -V | grep -q -e '\\<1\\.' -e '\\<2\\.0'" \
'source ~/.tmux/mode-mouse-1.9-2.0.conf' \
'source ~/.tmux/mode-mouse-2.1.conf'
# ------------------------------------------------------------------------
if-shell "tmux -V | grep -q -e '\\<1\\.' -e '\\<2\\.[0-5]'" \
'source ~/.tmux/vi-copy-mode-pre-2.6.conf' \
'source ~/.tmux/vi-copy-mode-2.6.conf'
# ------------------------------------------------------------------------
if-shell "tmux -V | grep -q -e '\\<1\\.9' -e '\\<[2-9]\\.'" \
'source ~/.tmux/current-path-1.9+.conf'
# ------------------------------------------------------------------------
if-shell "tmux -V | grep -q -e '\\<1\\.' -e '\\<2\\.[0-8]'" \
'source ~/.tmux/style-before-2.9.conf'
if-shell "tmux -V | grep -q -e '\\<2\\.9' -e '\\<3\\.'" \
'source ~/.tmux/style-after-2.9.conf'
# ------------------------------------------------------------------------
source ~/.tmux/scripts/fit.conf
# tmux.conf
# Vi copypaste mode
# in 2.6 https://github.com/tmux/tmux/commit/76d6d3641f271be1756e41494960d96714e7ee58
bind-key -Tcopy-mode-vi v send -X begin-selection
bind-key -Tcopy-mode-vi C-v send -X begin-selection \; send -X rectangle-toggle
bind-key -Tcopy-mode-vi y send -X copy-selection-and-cancel
# tmux.conf
# Vi copypaste mode
set-window-option -g mode-keys vi
bind-key -t vi-copy v rectangle-toggle
bind-key -t vi-copy C-v begin-selection
bind-key -t vi-copy y copy-selection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment