Created
November 4, 2019 07:07
-
-
Save linuxmail/8585b15b74041a6ddb6bd6b2ae22fe01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config file for TMUX 2.1 | |
# http://www.cs.ru.nl/~gdal/dotfiles/.tmux.conf | |
# good practice: don't use different aliases for the same command | |
# set --> set-option | |
# setw --> set-window-option | |
# run --> run-shell | |
# bind --> bind-key | |
# -r flag: enable keep hitting bind key without prefix | |
# -n flag: enable bind key without prefix | |
# -g flag: global | |
# always use bash :) | |
set -g default-shell /bin/bash | |
set -g default-terminal "screen-256color" | |
set -g default-command "bash" | |
# command history | |
set -g history-limit 100000 | |
# set 1 default first window number | |
set -g base-index 1 | |
setw -g pane-base-index 1 | |
# use unicode | |
# set -g utf8 on | |
# set -g status-utf8 on | |
# use xterm keys | |
setw -g xterm-keys on | |
# no more bell messages | |
set -g bell-action any | |
set -g visual-bell off | |
set -g visual-activity off | |
set -g visual-silence off | |
# When a smaller terminal connects to a tmux client, it shrinks to fit it. | |
setw -g aggressive-resize on | |
# kill pane/window/session | |
bind x confirm-before -p 'Kill pane (y/N)?' kill-pane | |
bind X confirm-before -p 'Kill session (y/N)?' ' \ | |
run-shell " \ | |
if [ \$(tmux list-sessions | wc -l) -ge 2 ]; then \ | |
tmux switch-client -ln; \ | |
fi; \ | |
tmux kill-session -t \"#S\"; \ | |
tmux refresh-client -S; \ | |
"' | |
bind C-x command-prompt -p 'Windows to kill:' ' \ | |
run-shell " \ | |
for w in \$(echo %% | sort -n -r); do \ | |
tmux kill-window -t \$w; \ | |
done; \ | |
"' | |
bind C-d run-shell " \ | |
if [ #{session_windows} -eq 1 ] && \ | |
[ #{window_panes} -eq 1 ] && \ | |
[ #{pane_current_command} = 'bash' ]; then \ | |
if [ \$(tmux list-sessions | wc -l) -ge 2 ]; then \ | |
tmux switch-client -ln; \ | |
fi; tmux kill-session -t \"#S\"; \ | |
else \ | |
tmux display-message \"Ignoring kill session...\"; \ | |
fi; \ | |
" | |
bind D confirm-before -p 'Kill tmux (y/N)?' ' \ | |
run-shell " \ | |
for s in \$(tmux list-sessions -F \"\##{session_name}\"); do \ | |
for w in \$(tmux list-windows -t \$s -F \"##{window_index}\"); do \ | |
for p in \$(tmux list-panes -t \"\$s:\$w\" -F \"##{pane_index}\"); do \ | |
t=\"\$s:\$w.\$p\"; \ | |
bin=\$(tmux display-message -t \$t -p -F \"##{pane_current_command}\"); \ | |
if [ \"\$bin\" = \"vim\" ]; then \ | |
tmux send-keys -t \$t Escape; \ | |
tmux send-keys -t \$t :qa; \ | |
tmux send-keys -t \$t Enter; \ | |
sleep 0.5; tmux refresh-client -S; \ | |
bin=\$(tmux display-message -t \$t -p -F \"##{pane_current_command}\"); \ | |
if [ \"\$bin\" = \"vim\" ]; then \ | |
tmux send-keys -t \$t Escape; \ | |
tmux select-pane -t \$t; \ | |
tmux select-window -t \"\$s:\$w\"; \ | |
tmux display-message \"Exit vim and re-run the command...\"; \ | |
exit 0; \ | |
fi; \ | |
fi; \ | |
done; \ | |
done; \ | |
done; \ | |
tmux confirm-before -p \"Confirm kill tmux (y/N)?\" kill-server; \ | |
"' | |
# tmux confirm-before -p "Proceed to kill server (y/N)?" kill-server | |
# force a reload of the config file | |
bind r source-file ~/.tmux.conf\; display-message "Config reloaded..." | |
# enabele mouse support | |
set -g mouse on | |
# toggle print to all panes in a window at once!! | |
bind e setw synchronize-panes | |
# refresh time interval, escape pause time and message time | |
set -g status-interval 1 | |
set -sg escape-time 0 | |
set -g display-time 1500 | |
set -g display-panes-time 10000 | |
# act like gnu screen | |
unbind C-b | |
set -g prefix C-a | |
# for nested tmux sessions, with prefix 'C-a C-s' | |
bind C-s send-prefix | |
# clear terminal in focus | |
bind C-t run-shell ' \ | |
bin=$(tmux display-message -p -F "#{pane_current_command}"); \ | |
if [ "$bin" = "bash" ]; then \ | |
tmux send-keys C-c; \ | |
tmux send-keys clear; \ | |
sleep 0.1;\ | |
tmux send-keys Enter; \ | |
fi;\ | |
'\; clear-history\; display-message "History cleared..."\; | |
# act like vim | |
setw -g mode-keys vi | |
unbind [ | |
bind v copy-mode | |
bind C-v copy-mode | |
bind -Tcopy-mode-vi C-e send start-of-line | |
bind -Tcopy-mode-vi C-r send end-of-line | |
bind -Tcopy-mode-vi e send start-of-line | |
bind -Tcopy-mode-vi r send end-of-line | |
bind -Tcopy-mode-vi v send begin-selection | |
bind -Tcopy-mode-vi V send rectangle-toggle | |
bind -Tcopy-mode-vi K send halfpage-up | |
bind -Tcopy-mode-vi J send halfpage-down | |
bind -Tcopy-mode-vi h send cursor-left | |
bind -Tcopy-mode-vi j send cursor-down | |
bind -Tcopy-mode-vi k send cursor-up | |
bind -Tcopy-mode-vi l send cursor-right | |
bind -Tcopy-mode-vi Escape send cancel | |
bind -Tcopy-mode-vi f send cancel | |
bind -Tcopy-mode-vi C-f send cancel | |
bind -Tcopy-mode-vi C-y send copy-pipe "cat | xsel -i -b" | |
bind -Tcopy-mode-vi Y send copy-pipe "cat | xclip -i" | |
bind -Tcopy-mode-vi y send copy-pipe "cat > ~/.buffer" | |
bind C-p run-shell "tmux set-buffer \"$(xsel --clipboard)\"; tmux paste-buffer" | |
bind P run-shell "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer" | |
bind p run-shell "tmux set-buffer \"\$(cat ~/.buffer)\"; tmux paste-buffer" | |
bind -Tcopy-mode-vi y send C-y copy-pipe "cat | xsel -i -b" | |
bind -Tcopy-mode-vi y send copy-pipe "cat | xclip -i" | |
# fix for weird output upon copy | |
set -g set-clipboard off | |
# workaround for global copy: copy to and from file buffer | |
# bind -t vi-copy y copy-pipe "cat >~/.copybuffer" | |
# bind p run "tmux load-buffer ~/.copybuffer; tmux paste-buffer;" | |
# reorder window numbering | |
set -g renumber-windows off | |
bind R \ | |
move-window -r\; \ | |
display-message "Windows reordered..." | |
# session navigation | |
bind s choose-session -F 'session #{session_name} #{?session_attached,(attached), } : #{session_windows} windows (#{window_name}#{pane_title})' \; refresh-client -S | |
bind n switch-client -n \; refresh-client -S | |
bind N switch-client -p \; refresh-client -S | |
# window/pane navigation | |
bind k select-pane -U\; refresh-client -S | |
bind j select-pane -D\; refresh-client -S | |
bind l select-pane -R\; refresh-client -S | |
bind h select-pane -L\; refresh-client -S | |
# window navigation | |
bind C-a last-window \; refresh-client -S | |
bind -r C-h previous-window \; refresh-client -S | |
bind -r C-l next-window \; refresh-client -S | |
bind 0 select-window -t 10 \; refresh-client -S | |
# window creation/splitting | |
bind [ split-window -h -p 50 -c "#{pane_current_path}" | |
bind ] split-window -v -p 50 -c "#{pane_current_path}" | |
bind c new-window -c "#{pane_current_path}" | |
bind C \ | |
run-shell 'tmux set-environment -g PANE_CURRENT_PATH #{pane_current_path}' \; \ | |
new-session 'cd $(eval "$(tmux showenv -g PANE_CURRENT_PATH)"; echo $PANE_CURRENT_PATH); bash -l' | |
bind i command-prompt -p 'Insert window at:' 'new-window -c "#{pane_current_path}" -a -t %1; swap-window -t -1' | |
bind I command-prompt -p 'New window at:' 'new-window -c "#{pane_current_path}" -t %1' | |
# resize pane | |
bind -r K resize-pane -U | |
bind -r J resize-pane -D | |
bind -r L resize-pane -R | |
bind -r H resize-pane -L | |
bind m resize-pane -Z # toggle maximize pane | |
# window manipulations | |
bind a command-prompt -p "Rename window:" "rename-window %%" | |
bind A command-prompt -p "Rename session:" "rename-session %%" | |
bind M command-prompt -p "Move window to:" "move-window -t %%" | |
bind S command-prompt -p "Swap window with:" "swap-window -t %%" | |
# set bar at the bottom (can also be 'top') | |
set-option -g status-position bottom | |
# tmux session name | |
set -g set-titles on | |
set -g set-titles-string '[#H:#S] #W #T' # session name, active program, pane title | |
# rename window with currently running command | |
setw -g automatic-rename on | |
# ------------------------------------------------------------------------------ | |
# tmux color scheme | |
# ------------------------------------------------------------------------------ | |
# used colours | |
GREY="colour233" | |
LGREY="colour235" | |
BLUE="colour4" | |
BLACK="#000000" | |
ORANGE="colour172" | |
GREEN="colour76" | |
WHITE="colour252" | |
# status bar formats | |
WINDOW="[#I #W#T]" | |
STATUS_LEFT=" #H #S #[fg=$WHITE]| " | |
STATUS_RIGHT="#{?client_prefix,PRE ,}#(bash -c 'source ~/.bash_tmux; tmuxstatusline;')%d-%m-%Y %H:%M " | |
setw -g window-status-current-format $WINDOW | |
setw -g window-status-format $WINDOW | |
set -g status-left-length 20 | |
set -g status-left-attr bright | |
set -g status-left $STATUS_LEFT | |
set -g status-right-length 40 | |
set -g status-right-attr dim | |
set -g status-right $STATUS_RIGHT | |
# default statusbar colors | |
set -g status-fg $WHITE | |
set -g status-bg $GREY | |
set -g status-attr dim | |
# default left status colors | |
set -g status-left-bg $GREY | |
set -g status-left-fg $BLUE | |
set -g status-left-attr bright | |
# default right status colors | |
set -g status-right-bg $GREY | |
set -g status-right-fg $WHITE | |
set -g status-right-attr dim | |
# default window title colors | |
setw -g window-status-fg $WHITE | |
setw -g window-status-bg $GREY | |
setw -g window-status-attr dim | |
# active windows status colors | |
setw -g window-status-current-fg $ORANGE | |
setw -g window-status-current-bg $GREY | |
setw -g window-status-current-attr bright | |
# last window status colors | |
setw -g window-status-last-fg white | |
setw -g window-status-last-bg $GREY | |
setw -g window-status-last-attr bright | |
# watch for activity in background windows | |
setw -g monitor-activity on | |
setw -g window-status-activity-fg $GREEN | |
setw -g window-status-activity-bg $GREY | |
setw -g window-status-activity-attr dim | |
# set active/pasive pane background colours | |
set -g window-style fg=default | |
set -g window-style bg=$GREY | |
set -g window-active-style fg=default | |
set -g window-active-style bg=$BLACK | |
# pane colors | |
set -g display-panes-active-colour $ORANGE | |
set -g display-panes-colour $WHITE | |
set -g pane-active-border-fg $LGREY | |
set -g pane-active-border-bg $GREY | |
set -g pane-border-fg $LGREY | |
set -g pane-border-bg $GREY | |
# message colors | |
set -g message-command-attr bright | |
set -g message-command-bg $ORANGE | |
set -g message-command-fg $GREY | |
set -g message-attr bright | |
set -g message-bg $ORANGE | |
set -g message-fg $GREY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment