-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmux.conf
279 lines (223 loc) · 10.2 KB
/
tmux.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# =========================================================================== #
# mbh tmux config
# =========================================================================== #
col_1=colour98 # main color
#col_1=green # main color
col_2=colour117 # deactivated tmux color
#col_2=cyan # deactivated tmux color
col_3=colour8 # deactivated inactive pane color
stat_left="➤"
# =========================================================================== #
# prefix stuff
# =========================================================================== #
unbind C-b
set -g prefix C-q
bind q send-prefix
# =========================================================================== #
# binds
# =========================================================================== #
# pane navigation
bind -n C-Up select-pane -U
bind -n C-Down select-pane -D
bind -n C-Left select-pane -L
bind -n C-Right select-pane -R
# pane resizing
bind -r C-Down resize-pane -D
bind -r C-Up resize-pane -U
bind -r C-Left resize-pane -L
bind -r C-Right resize-pane -R
# window navigation
bind -n S-Left previous-window
bind -n S-Right next-window
bind b previous-window
bind n next-window
# splits & new windows
bind s split-window -h -c "#{pane_current_path}"
bind x split-window -v -c "#{pane_current_path}"
bind c new-window
# close pane
bind -n C-w kill-pane
# scrollback
bind -n C-PPage copy-mode -u
unbind -T copy-mode C-Up
unbind -T copy-mode C-Down
# reload conf
bind r source-file ~/.tmux.conf \; display-message '★ conf reloaded ★'
# display panes info
bind a display-panes
# zoom in / out
bind z resize-pane -Z
bind l resize-pane -Z
bind m resize-pane -Z
# dump history to file
bind P command-prompt -p 'save history to filename:' -I '/tmp/dump.txt' 'capture-pane -S -32768 ; save-buffer %1 ; delete-buffer'
# open man
bind / command-prompt -p 'man' "split-window 'exec man %%'"
# toggle pane synchronization
bind y setw synchronize-panes \; display-message 'toggled pane synchronization'
# # conditional command tests
# is_ssh="ps -o state= -o comm= -t '#{pane_tty}' | \
# grep -iqE '^[^TXZ ]+ +(\\S+\\/)?ssh$' "
# bind h run "($is_ssh && tmux send-keys y) || tmux send-keys n"
# bind j if-shell "$is_ssh" "send-keys y" "send-keys n"
# =========================================================================== #
# tmux godmode, support nested tmux
# =========================================================================== #
# increment variable TMUX_NEST
set-environment -g 'TMUX_NEST' "0"
TMUX_NEST_INC='tmux set-environment -g TMUX_NEST $(($(tmux show-environment -g TMUX_NEST 2>/dev/null | cut -d'=' -f2 ) + 1))'
TMUX_NEST_DEC='tmux set-environment -g TMUX_NEST $(($(tmux show-environment -g TMUX_NEST 2>/dev/null | cut -d'=' -f2 ) - 1))'
TMUX_NEST_GET='tmux show-environment -g TMUX_NEST 2>/dev/null | cut -d'=' -f2 '
theme_on=" \
tmux set -g window-status-current-fg $col_1 ;\
tmux set -g status-right-fg $col_1 ;\
tmux set -g pane-active-border-fg $col_1 ;\
tmux set -g pane-border-fg default ;\
tmux set -g message-bg $col_1 ;\
tmux set -g status-left-fg default ;\
tmux set -g status-left $stat_left "
theme_off=" \
tmux set -g window-status-current-fg $col_2 ;\
tmux set -g status-right-fg $col_2 ;\
tmux set -g pane-active-border-fg $col_2 ;\
tmux set -g pane-border-fg colour8 ;\
tmux set -g message-bg $col_2 ;\
tmux set -g status-left-fg $col_2 ;\
tmux set -g status-left \"(inactive)\" "
# activate / deactivate tmux theme
bind F1 run "$theme_on"
bind F2 run "$theme_off"
# increase / decrease tmux nest counter
bind F3 run "$TMUX_NEST_INC"
bind F4 run "$TMUX_NEST_DEC"
# relay keys to inside tmux to switch theme on/off
in_on="tmux send-keys C-q F1"
in_off="tmux send-keys C-q F2"
# unbind all direct access keys (no prefix) and remove local prefix (switch it to C-b)
keys_unbind=" \
tmux unbind -n C-up ;\
tmux unbind -n C-down ;\
tmux unbind -n C-left ;\
tmux unbind -n C-right ;\
tmux unbind -n C-pageup ;\
tmux unbind -n C-w ;\
tmux unbind -n S-left ;\
tmux unbind -n S-right ;\
tmux set -g prefix C-b ;\
tmux unbind C-q "
# rebind all direct access keys (no prefix) and switch back prefix to C-q
keys_rebind=' \
tmux bind -n C-up select-pane -U ;\
tmux bind -n C-down select-pane -D ;\
tmux bind -n C-left select-pane -L ;\
tmux bind -n C-right select-pane -R ;\
tmux bind -n C-pageup copy-mode -u ;\
tmux bind -n C-w kill-pane ;\
tmux bind -n S-left previous-window ;\
tmux bind -n S-right next-window ;\
tmux set -g prefix C-q ;\
tmux unbind C-b '
# activate inner tmux & deactivate outer tmux
# this bind always stays activated, if local tmux is not currently active, just increase nest_counter & relay key
bind -n S-up run "$TMUX_NEST_INC" \; \
if-shell "tmux show-environment -g TMUX_NEST 2>/dev/null | cut -d'=' -f2 | grep '^1$' > /dev/null" \
'run "$in_on ; $keys_unbind ; $theme_off"' \
'send-keys S-up'
# reactivate outer tmux & deactivate inner tmux
# this bind always stays activated, decrease nest_counter, if nest counter reaches 0 => rebind all keys, if not relay key
bind -n S-down run "$TMUX_NEST_DEC" \; \
if-shell "tmux show-environment -g TMUX_NEST 2>/dev/null | cut -d'=' -f2 | grep '^0$' > /dev/null" \
'run "$in_off ; $keys_rebind ; $theme_on"' \
'send-keys S-down'
# =========================================================================== #
# mouse (tmux 2.3+)
# =========================================================================== #
set -g mouse on
# kill window
bind -n MouseUp2Status kill-window -t=
# reorder windows
bind -n MouseDrag1Status swap-window -t=
# new window on double click
bind -n DoubleClick1Status new-window
# clipboard
bind -T copy-mode MouseDragEnd1Pane send -X copy-selection-and-cancel\; run "tmux save-buffer - | xclip -i -sel clipboard > /dev/null"
bind -T copy-mode Enter send -X copy-selection-and-cancel\; run "tmux save-buffer - | xclip -i -sel clipboard > /dev/null"
# right click & middle click => paste
bind -n MouseDown3Pane run "tmux set-buffer \"$(xclip -o -sel clipboard)\"; tmux paste-buffer"
bind -n MouseDown2Pane run "tmux set-buffer \"$(xclip -o -sel clipboard)\"; tmux paste-buffer"
# =========================================================================== #
# config
# =========================================================================== #
# term
set -g default-terminal "screen-256color" # we want colors
set-window-option -g xterm-keys on # dont hijack alt+left / alt+backspace / ...
set -g history-limit 40000 # backlog
# compatibility with putty for ctrl+arrows
#set -g terminal-overrides "xterm*:kLFT5=\eOD:kRIT5=\eOC:kUP5=\eOA:kDN5=\eOB:smkx@:rmkx@"
#set -g terminal-overrides 'xterm*:smcup@:rmcup@'
set -ga terminal-overrides ",*:Tc" # for 24bits colors
# windows
set -g set-titles on
set-window-option -g automatic-rename on
set -g renumber-windows on
# =========================================================================== #
# status bar
# =========================================================================== #
# status bar globals
set -g status-bg default
set -g status-fg default
set -g status-interval 5
set -g status-justify left
# left hand status bar
set -g status-left-length 30
set -g status-left $stat_left
# selected window status
setw -g window-status-current-attr none
setw -g window-status-current-bg default
setw -g window-status-current-fg $col_1
setw -g window-status-current-format " ★ #I #W"
# unselected windows status
setw -g window-status-attr none
setw -g window-status-bg default
setw -g window-status-fg white
setw -g window-status-format " ☆ #I #W"
# status bar right (time / date)
# set -g status-right '☀ %d/%m ⌛%H:%M ' #⌛
set -g status-right '%d/%m %H:%M '
set -g status-right-length 30
set -g status-right-bg default
set -g status-right-fg $col_1
# =========================================================================== #
# other colors
# =========================================================================== #
# messages
set -g message-attr dim
set -g message-fg black
set -g message-bg $col_1
set -g message-command-attr dim
set -g message-command-fg black
set -g message-command-bg $col_1
# scroll indicator
set -g mode-fg black
set -g mode-bg $col_1
set -g mode-attr dim
# pane colors
set -g pane-active-border-fg $col_1
set -g pane-active-border-bg default
set -g pane-border-fg default
set -g pane-border-bg default
# less colors for when we use the binding C-q /
set-environment -g 'LESS_TERMCAP_mb' "\e[01;31m"
set-environment -g 'LESS_TERMCAP_md' "\e[01;38;5;12m"
set-environment -g 'LESS_TERMCAP_me' "\e[0m"
set-environment -g 'LESS_TERMCAP_so' "\e[30m\e[42m"
set-environment -g 'LESS_TERMCAP_se' "\e[0m"
set-environment -g 'LESS_TERMCAP_us' "\e[04;38;5;6m"
set-environment -g 'LESS_TERMCAP_ue' "\e[0m"
# =========================================================================== #
# not main tmux? starting a secondary tmux inside ssh?
# =========================================================================== #
# starting inside ssh? deactivate them right away & set mouse off
if-shell "env | grep SSH_CLIENT" '\
run "$theme_off" ;\
set -g mouse off '