forked from braintreeps/vim_dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tmux_example.conf
219 lines (174 loc) · 7.83 KB
/
tmux_example.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# split windows like vim
# vim's definition of a horizontal/vertical split is reversed from tmux's
bind s split-window -v -c "#{pane_current_path}"
bind ^s split-window -v -c "#{pane_current_path}"
bind _ split-window -fv -c "#{pane_current_path}"
bind v split-window -h -c '#{pane_current_path}'
bind ^v split-window -h -c "#{pane_current_path}"
bind | split-window -fh -c '#{pane_current_path}'
# open panes in same path when using canonical tmux splits
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
if-shell "tmux -V | awk '{exit ($2 >= 3.2) ? 0 : 1}'" \
"bind '`' run -C \"display-popup -d '#{pane_current_path}' -xC -yC -w'90%' -h'90%' -E 'tmux attach -t #S-popup || tmux new -s #S-popup'\""
# Provide command to generate a 2:1 ratio layout
bind @ \
split-window -h -c "#{pane_current_path}" -p 33 \;\
select-pane -L \;\
# move around panes with hjkl, as one would in vim after pressing ctrl-w
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind ^h select-pane -L
bind ^j select-pane -D
bind ^k select-pane -U
bind ^l select-pane -R
# resize panes like vim
# feel free to change the "1" to however many lines you want to resize by, only
# one at a time can be slow
bind -r < resize-pane -L 10
bind -r > resize-pane -R 10
bind -r - resize-pane -D 10
bind -r + resize-pane -U 10
bind = select-layout tiled
# bind : to command-prompt like vim
# this is the default in tmux already
bind : command-prompt
# Confirm before changing your bespoke layout to zebra stripes
bind Space confirm next-layout
bind C-d if -F '#{session_many_attached}' \
'confirm-before -p "Detach other clients? (y/n)" "detach -a"' \
'display "Session has only 1 client attached"'
# session management
bind C new-session
bind L choose-session
# vi-style controls for copy mode
setw -g mode-keys vi
# Set the prefix to ^A, like screen
unbind C-b
set -g prefix ^A
bind a send-prefix
# Start numbering windows at 1
set -g base-index 1
# Renumber tmux windows
bind R move-window -r
bind ^a last-window # toggle last window like screen
set -g update-environment "DISPLAY WINDOWID SSH_AUTH_SOCK SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION"
bind K confirm kill-server
bind X confirm kill-window
# avoid lag when pressing `esc` in vim
# https://stackoverflow.com/a/33812578
set -s escape-time 0
# longer scrollback
set -g history-limit 10000
set -g status-interval 1
if-shell "tmux -V | awk '{exit ($2 < 2.9) ? 0 : 1}'" \
'set -g status-bg default'
if-shell "tmux -V | awk '{exit ($2 >= 2.9) ? 0 : 1}'" \
'set -g status-bg terminal'
set -g status-fg white
# Notify clients on focus
set -g focus-events on
# left side of status bar holds "(>- session name -<)"
set -g status-left-length 100
set -g status-left ''
if-shell "tmux -V | awk '{exit ($2 < 2.9) ? 0 : 1}'" \
'set -g status-left-bg green ;\
set -g status-left-fg black ;\
set -g status-left-attr bold'
if-shell "tmux -V | awk '{exit ($2 >= 2.9) ? 0 : 1}'" \
'set -g status-left-style bg=green,fg=black,bold'
# right side of status bar holds "[host name] (date time)"
set -g status-right-length 100
set -g status-right '#[fg=colour214,bg=colour235] #H#[fg=colour238]:#[fg=colour178]#S #[fg=colour039,bg=colour238] %y.%m.%d %H:%M '
if-shell "tmux -V | awk '{exit ($2 < 2.9) ? 0 : 1}'" \
'set -g status-right-fg black ;\
set -g status-right-attr bold'
if-shell "tmux -V | awk '{exit ($2 >= 2.9) ? 0 : 1}'" \
'set -g status-right-style fg=black,bold'
# make background window look like white tab
set-window-option -g window-status-format '#[fg=colour214,bg=colour235] #I #[fg=white,bg=colour236] #{?window_zoomed_flag,#[fg=colour44](,}#W#{?window_zoomed_flag,#[fg=colour44]),} #{?pane_synchronized,#[fg=brightred](sync) ,}#[default]'
if-shell "tmux -V | awk '{exit ($2 < 2.9) ? 0 : 1}'" \
'set-window-option -g window-status-bg default ;\
set-window-option -g window-status-fg white ;\
set-window-option -g window-status-attr none'
if-shell "tmux -V | awk '{exit ($2 >= 2.9) ? 0 : 1}'" \
'set-window-option -g window-status-style bg=default,fg=white,none'
# make foreground window look like bold yellow foreground tab
set-window-option -g window-status-current-format '#[fg=black,bg=colour214] #I #[fg=brightwhite,bg=colour238] #{?window_zoomed_flag,#[fg=colour44](,}#W#{?window_zoomed_flag,#[fg=colour44]),} #{?pane_synchronized,#[fg=brightred](sync) ,}#[default]'
if-shell "tmux -V | awk '{exit ($2 < 2.9) ? 0 : 1}'" \
'set-window-option -g window-status-current-attr none'
if-shell "tmux -V | awk '{exit ($2 >= 2.9) ? 0 : 1}'" \
'set-window-option -g window-status-current-style none'
# active terminal yellow border, non-active white
if-shell "tmux -V | awk '{exit ($2 < 2.9) ? 0 : 1}'" \
'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 colour214'
if-shell "tmux -V | awk '{exit ($2 >= 2.9) ? 0 : 1}'" \
'set -g pane-border-style bg=default,fg=colour238 ;\
set -g pane-active-border-style bg=default,fg=colour214'
if-shell 'infocmp tmux-256color >/dev/null 2>&1' \
"set -g default-terminal tmux-256color" \
"set -g default-terminal screen-256color"
set -as terminal-overrides ',xterm*:sitm=\E[3m'
# disable mouse mode by default
if-shell "tmux -V | awk '{exit ($2 > 2.0) ? 0 : 1}'" \
'set -g mouse off'
if-shell "tmux -V | awk '{exit ($2 < 2.1) ? 0 : 1}'" \
'set -g mode-mouse off ;\
set -g mouse-resize-pane off ;\
set -g mouse-select-pane off ;\
set -g mouse-select-window off'
# Toggle mouse on with m
if-shell "tmux -V | awk '{exit ($2 < 2.1) ? 0 : 1}'" \
"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'"
if-shell "tmux -V | awk '{exit ($2 > 2.0) ? 0 : 1}'" \
"bind m \ set -g mouse on \\;\
display 'Mouse: ON'"
# Toggle mouse off with M
if-shell "tmux -V | awk '{exit ($2 < 2.1) ? 0 : 1}'" \
"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'"
if-shell "tmux -V | awk '{exit ($2 > 2.0) ? 0 : 1}'" \
"bind M \
set -g mouse off \\;\
display 'Mouse: OFF'"
# reload tmux config file with C-a r
bind r source ~/.tmux.conf
# Create a new window and prompt for name
bind N command-prompt "new-window -n '%%' -c '#{pane_current_path}'"
bind c new-window -c '#{pane_current_path}'
# Rebind prefix to b
bind B confirm-before -p "Change prefix to C-b?" 'set -g prefix ^b'
bind A confirm-before -p "Change prefix to C-a?" 'set -g prefix ^a'
# Toggle synchronize-panes with C-a y
bind y run 'tmux showw synchronize-panes | grep " on" >/dev/null && tmux set synchronize-panes || tmux run -C "confirm-before -p \"Synchronize panes?\" \"set synchronize-panes\""'
# Save tmux history - http://unix.stackexchange.com/questions/26548/write-all-tmux-scrollback-to-a-file
bind S command-prompt -p 'save history to filename:' -I '/tmp/tmux.history' 'capture-pane -S -32768 ; save-buffer %1 ; delete-buffer'
# Fix copy/paste on MacOS: https://thoughtbot.com/blog/how-to-copy-and-paste-with-tmux-on-mac-os-x
if-shell "test -f /usr/local/bin/reattach-to-user-namespace" 'set-option -g default-command "reattach-to-user-namespace -l zsh"'
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-resurrect'
# override default resurrect bindings to avoid conflict with existing shortcut
set -g @resurrect-save 'Z'
set -g @resurrect-restore 'R'
set -g @resurrect-processes 'ssh'
# Source extra global tmux config if it exists
if-shell "test -f /etc/tmux.conf.global" "source /etc/tmux.conf.global"
# Source extra user tmux config if it exists
if-shell 'test -f ~/.tmux.conf.user' 'source ~/.tmux.conf.user'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'