Skip to content

Instantly share code, notes, and snippets.

@pldubouilh
Last active April 21, 2020 13:10
Show Gist options
  • Select an option

  • Save pldubouilh/52fe2e7f24228d4e978375ab4487441e to your computer and use it in GitHub Desktop.

Select an option

Save pldubouilh/52fe2e7f24228d4e978375ab4487441e to your computer and use it in GitHub Desktop.
same-config-on-multiple-sessions kind of tmux
set-hook -g after-new-session 'if -F "#{==:#{session_name},home}" "source ~/.tmux.home" "source ~/.tmux.server"'
set-hook -g client-session-changed 'if -F "#{==:#{session_name},home}" "source ~/.tmux.home" "source ~/.tmux.server"'
# No status
#display ssh
set-option -g status off
# disable all binding BUT the ones to change session
set -g mouse off
set -g prefix C-1
unbind C-z
unbind -n S-Up
unbind -n S-Left
unbind -n S-Right
unbind -n C-n
unbind -n C-Left
unbind -n C-Right
unbind -n C-Up
unbind -n C-Down
unbind -n M-Up
unbind -n M-Down
unbind -n M-Right
unbind -n M-Left
unbind -n C-S-Left
unbind -n C-S-Right
unbind -n C-M-Left
unbind -n C-M-Right
unbind -n C-t
#!/bin/bash
# tmux helper. http://unix.stackexchange.com/a/325816/119298
if [[ $(tmux show-window-option synchronize-panes) == *on ]]
then tmux set-window-option -q synchronize-panes off
restore="tmux set-window-option -q synchronize-panes on"
fi
tmux list-panes -F '#{window_index} #{pane_index}' |
while read winid pane
do tmux send-keys -t $winid.$pane $pane
done
$restore

Copy tmux.home on remote ends as .tmux.conf, and amend it to change the colors to differentiate them.

Start main tmux session on connecting host with tmux new -s home, to have the same shortcut on all sessions, appart from CTRL+S to switch between sessions

# >>>>>>>>>>>>> CHANGE COLORS ON SERVERS <<<<<<<<<<<<<<<<
set -g window-status-current-style "fg=red"
set -g pane-active-border-style "fg=red"
# Ctrl + s for sesssion switch, n for new, w to kill
bind -n C-s switch-client -n
bind -n C-M-w kill-session
bind -n C-M-n new-session
# swap window pos
bind -n C-M-Left swap-window -t -1
bind -n C-M-Right swap-window -t +1
# Long hist
set-option -g history-limit 10000
# Shift l/r for other windows
bind -n S-Left previous-window
bind -n S-Right next-window
# status
bind -n S-Up set status
set-option -g status-position top
set-window-option -g xterm-keys on
# Ctrl+Z for meta
unbind C-b
set -g prefix C-z
bind C-z send-prefix
# YAY MOUSE
set -g mouse on
unbind -n MouseDown3Pane
# handy sync tool to spit number of pane in shell
# tip: goes well with :set synchronize-panes on
bind-key w run-shell "~/./.tmux.sync.number"
# Ctrl + l/r/u/d for pane nav. n for new window
bind -n C-Left select-pane -L
bind -n C-Right select-pane -R
bind -n C-Up select-pane -U
bind -n C-Down select-pane -D
bind -n C-n new-window
# Alt l/r to enter copy mode, space to start cp, enter to copy, esc to deselect, right click (or Q) to exit cp
set -g mode-keys vi
bind -n M-Left copy-mode
bind -n M-Right copy-mode
bind -n -T copy-mode-vi Space send -X begin-selection
bind -n -T copy-mode-vi Escape send -X clear-selection
bind -n -T copy-mode-vi Enter send -X copy-pipe 'xclip -in -selection clipboard' \; send -X clear-selection
bind -n -T copy-mode-vi MouseDown3Pane send -X cancel
bind -n -T copy-mode-vi C-Down select-pane -D
bind -n -T copy-mode-vi C-Up select-pane -U
# Disable copy-selection-and-go-to-end behaviour when copying
bind -n -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe 'xclip -in -selection clipboard' \; send -X clear-selection
# Colors onwards
set -g status-style "bg=default"
set -g status-style "fg=white"
set -g window-status-style "fg=#666666"
set -g status-left " "
set -g status-justify left
setw -g window-status-format ' #(echo "#{window_name}") '
setw -g window-status-current-format ' #(echo "#{window_name}") '
set -g status-right-length 80
set -g status-right '#(exec tmux ls| cut -d ":" -f 1 |tr "\\n" " " )'
#set -g lock-after-time 5
#set -g lock-command "cmatrix -s -C blue"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment