-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmux.conf
396 lines (298 loc) · 13.9 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
####################################
## _______________________________
## /\ \
## \_| __ |
## | / /_____ ___ __ ___ __ |
## | / __/ __ `__ \/ / / / |/_/ |
## | / /_/ / / / / / /_/ /> < |
## | \__/_/ /_/ /_/\__,_/_/|_| |
## | -by m42nk |
## | __________________________|_
## \_/____________________________/
##
#####################################
## vim: ft=tmux fdm=marker fdl=0
#####################################
#####################################
## Variables
#####################################
_cfgDir="~/.config/tmux"
_cfgCustomDir="${_cfgDir}/custom"
_cfgScriptsDir="${_cfgDir}/scripts"
_confDefault="${_cfgDir}/defaults/v3.4.conf"
_confCurr="${_cfgDir}/tmux.conf"
#####################################
## Prefix
#####################################
unbind C-b
set -g prefix '`'
bind '`' send-prefix # send backtick if typed twice
set -g prefix2 C-b
bind 'C-b' send-prefix -2
#####################################
## Terminal Settings
#####################################
# MacOS ships with a very old ncurses and terminfo.
# If tmux-256color is not recognized in your mac, update terminfo.
# -- https://gist.github.com/bbqtd/a4ac060d6f6b9ea6fe3aabe735aa9d95
# -- https://ryantravitz.com/blog/2023-02-18-pull-of-the-undercurl/
set -g default-terminal "tmux-256color" # TODO: check if setting this value to xterm-kitty will solve paste control codes issue (weird char when pasting)
set -gu default-command
set -g default-shell "$SHELL"
# TODO: use proper, next
set-option -ga terminal-overrides ',xterm-kitty:cnorm=\E[?12h\E[?25h'
# set -gas terminal-overrides "*:Tc" # true color support
# set -gas terminal-overrides "*:RGB" # true color support
# set -as terminal-overrides ',*:Smulx=\E[4::%p1%dm' # undercurl support
# set -as terminal-overrides ',*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m' # underscore colours - needs tmux-3.0
## Extended keys (ctrl+enter, shift+enter, etc), required in tmux 3.5a
# https://github.com/tmux/tmux/wiki/Modifier-Keys#extended-keys
# set -s extended-keys on
# set -s extended-keys-format csi-u # for kitty
# set -as terminal-features ",*:extkeys"
#####################################
## General Options
#####################################
## Server options
set -sg focus-events on # Enable focus-events inside tmux (focus on terminal window)
set -sg escape-time 0 # Reduce delay when pressing <Esc>
set -sg repeat-time 500 # How long tmux wait for repeatable (-r) bind-key
## Session options
set -g detach-on-destroy off # Switch to other when session is closed (don't exit tmux)
set -g history-limit 100000 # Increase scrollback buffer size
set -g set-titles on # Allow tmux to change terminal title
set -g mouse on # Enable mouse (e.g. to drag pane edge for resizing)
## Window options
set -wg wrap-search on # Search wrap around
# set -wg monitor-activity on # Highlight tmux window if it's update when out of focus; disabled, too noisy, nvim will always trigger
set -wg popup-border-lines rounded # Make popup window border rounded
## Pane options
set -g scroll-on-clear on # Scroll to bottom on clear
## Rename OS Window
set -g set-titles on
set -g set-titles-string "#S:#I:#W - tmux #{session_alerts}"
#####################################
## Numbering
#####################################
set -g renumber-windows on # Renumber windows when a window is closed
set -g base-index 1 # Start windows numbering at 1
set -wg pane-base-index 1 # Start pane numbering at 1
## set -g session-base-index 1 # <- This option doesn't exists, so we use hooks to do that (check below)
#####################################
## Clipboard
#####################################
## Enable clipboard
set -sg set-clipboard on
## Clipboard program on Linux
if -b 'command -v xsel' {
set -s copy-command "xsel -i"
}
## Clipboard program on MacOS
if -b 'command -v pbcopy' {
set -s copy-command 'pbcopy'
}
#####################################
## Pene related options
#####################################
set -wg pane-border-lines single # Pane border style
set -wg pane-border-indicators both # Use border color and arrow to indicate active
## Dim inactive pane
set -g window-style "bg=black" # Dim pane background
set -g window-active-style "bg=terminal" # Transparent pane background (active)
set -wg pane-border-style "fg=brightblack,bg=black" # Match inactive pane background
set -wg pane-active-border-style "fg=green,bg=black" # TODO: can make 'Green' as primary color
## Pretty pane title
paneTitleHomeDir=" Home"
paneTitleOtherDir=" #{b:pane_current_path}"
isPanePathHome="#{==:#{pane_current_path},${HOME}}"
paneTitleDir="#{?$isPanePathHome,$paneTitleHomeDir,$paneTitleOtherDir}"
paneTitleDefaultFormat="#{pane_title}"
paneTitleFormat="$paneTitleDir #{pane_current_command}"
isPaneTitleDefault="#{==:#{pane_title},#{host}}"
set -g pane-border-format "[#P: #{?$isPaneTitleDefault,$paneTitleFormat,$paneTitleDefaultFormat}]"
#####################################
## Vim motion in copy-mode
#####################################
setw -g mode-keys vi
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi y send -X copy-pipe-and-cancel
bind -T copy-mode-vi 'y' send -X copy-selection
bind -T copy-mode-vi 'C-v' send -X rectangle-toggle # <C-v><space> for block-selection mode
#####################################
## Status line
#####################################
source-file "${_cfgDir}/status.tmux.conf"
#####################################
## Command Alias
#####################################
set -s command-alias[100] rename-pane='select-pane -T'
#####################################
## Keybinding
## -r = keybinding is repeatable (can be pressed multiple time without prefix repeatedly)
#####################################
## Reload config
bind r run "\
tmux source '$_confDefault' '$_confCurr' 2>&1 && \
tmux display-message 'Config reloaded!' \
"
## Command prompt
bind ':' command-prompt
#####################################
## Keybinding - Pane Navigation
#####################################
## Vim-aware movement, vim should also be configured to be tmux-aware
## -- eg: https://github.com/christoomey/vim-tmux-navigator
## -- Detect if current pane is running vim programs (vim, nvim, vimdiff, etc)
_isVim="ps -o state= -o comm= -t '#{pane_tty}' | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind h if-shell "$_isVim" "send-keys C-w h" "select-pane -L"
bind j if-shell "$_isVim" "send-keys C-w j" "select-pane -D"
bind k if-shell "$_isVim" "send-keys C-w k" "select-pane -U"
bind l if-shell "$_isVim" "send-keys C-w l" "select-pane -R"
## Jump
bind F display-panes -d 0
#####################################
## Keybinding - Pane Manipulation
#####################################
## Toggle Pane Border
bind b set pane-border-status
## Create pane (Split window)
bind '\' if -F "#{window_zoomed_flag}" 'select-pane -l' 'split-window -h -c "#{pane_current_path}"' # Backslash split vertical (`|` without shift)
bind - if -F "#{window_zoomed_flag}" 'select-pane -l' 'split-window -v -c "#{pane_current_path}"' # Minus split horizontal
## Move pane to new window
bind ! break-pane ';' display-message "Pane moved!"
## Zoom pane (toggle)
bind Enter resize-pane -Z
## Move pane (Mark-Join flow)
## -- Steps: mark pane with <prefix>m, move to desired session/window, join pane with <prefix><shift>J
bind m select-pane -m ';' display-message "#{?pane_marked,Mark,Unmark}ed pane: #P"
bind M select-pane -M # unmark
bind J join-pane -h
## Rename pane
bind > command-prompt -I "#{pane_title}" -p 'rename-pane:' 'select-pane -T "%%"'
#####################################
## Keybinding - Window Navigation
#####################################
## Default navigation
bind 1 select-window -t :=1
bind 2 select-window -t :=2
bind 3 select-window -t :=3
bind 4 select-window -t :=4
bind 5 select-window -t :=5
## Prev/Next Window (repeatable)
bind -r C-p previous-window
bind -r C-n next-window
## Search window by match
bind C-f command-prompt -p "match-window: " 'find-window -t %%'
#####################################
## Keybinding - Window Manipulation
#####################################
## Create window
bind c new-window -c "#{pane_current_path}" # Create at the end of window list (in status bar)
bind C new-window -a -c "#{pane_current_path}" # Create next to current active window (in status bar)
## Change layout
bind -r Space next-layout # Cycle window layout
bind -r C-Space previous-layout # Cycle window layout
## Rotate panes position
bind -r o rotate-window
# Move to last active window
bind -r Tab last-window
## Rename window
bind , command-prompt -I "#{window_name}" -p 'rename-window:' 'rename-window "%%"'
## Swap window
bind w switch-client -T swaping-window
bind -T swaping-window p swap-window -d -t -1 ';' switch-client -T swaping-window
bind -T swaping-window n swap-window -d -t +1 ';' switch-client -T swaping-window
bind -T swaping-window h swap-window -d -t -1 ';' switch-client -T swaping-window
bind -T swaping-window l swap-window -d -t +1 ';' switch-client -T swaping-window
#####################################
## Keybinding - Session Manipulation
#####################################
## Create session
bind N new-session # Create new session
## Launcher
bind n display-popup -T "[Launcher]" -E -h '80%' -w '80%' "${_cfgScriptsDir}/launcher.sh"
bind C-n run "${_cfgScriptsDir}/sessionizer-rename-session.sh"
# Rename session
bind . command-prompt -I "#{session_name}" -p 'rename-session:' 'rename-session "%%"'
## TODO: unmodified
## Fuzzy chooser
bind i display-popup -E -h '80%' -w '80%' "${_cfgScriptsDir}/fuzzy-chooser.sh"
## Scratch
bind q run "DIR='#{pane_current_path}' ${_cfgScriptsDir}/popup-window.sh"
## Clear scrollback buffer (since we use scroll-on-clear)
bind C-l clear-history ';' display-message "Scrollback buffer cleared"
## Go into copy-mode-vi and start searching
bind / copy-mode ';' send-key ?
## Save scrollback buffer to a file
bind P command-prompt -p 'save history to filename:' -I '~/tmux.history' 'capture-pane -J -S -; save-buffer %1 ; delete-buffer'
#####################################
## Key menu
#####################################
## Delete/Detach/Kill
bind d display-menu -x 0 -y S -T "Delete/Detach/Kill" \
"Window" w "kill-window -t #{window_id}" \
"Session" s "kill-session -t #{session_id}" \
"Pane" p "kill-pane -t #{pane_id}" \
"Pane (quick)" d "kill-pane -t #{pane_id}" \
"Client (back to terminal)" q "detach-client" \
"Server" S "confirm-before -p 'Kill tmux server?' 'kill-server'" \
"" \
"Other window except current" W "kill-window -t #{window_id} -a" \
"Other pane except current" P "kill-pane -t #{pane_id} -a" \
"Detached session" D "run 'tmux list-sessions | grep -v attached | cut -d: -f1 | xargs -t -n1 tmux kill-session -t'" \
"" \
"Long running (select)" f "run 'tmux display-popup -E -h '80%' -w '80%' ${_cfgScriptsDir}/fuzzy-kill-long-running-process.sh'"
## Rename
bind R display-menu -x 0 -y S -T "Rename" \
"Session" s "command-prompt -I '#{session_name}' -p 'rename-session:' 'rename-session %%'" \
"Window" w "command-prompt -I '#{window_name}' -p 'rename-window:' 'rename-window %%'" \
"Pane" p "command-prompt -I '#{pane_title}' -p 'rename-pane:' 'select-pane -T %%'" \
"Session match cwd" d "rename-session #{b:pane_current_path}; attach -c #{b:pane_current_path}"
#####################################
## Keybind chording with key-table
#####################################
## Resize
bind C-r switch-client -T resize
bind -T resize -r x resize-pane -x 1 ';' switch-client -T resize
bind -T resize -r y resize-pane -y 1 ';' switch-client -T resize
bind -T resize -r H resize-pane -L 5 ';' switch-client -T resize
bind -T resize -r J resize-pane -D 5 ';' switch-client -T resize
bind -T resize -r K resize-pane -U 5 ';' switch-client -T resize
bind -T resize -r L resize-pane -R 5 ';' switch-client -T resize
bind -T resize -r h resize-pane -L 10 ';' switch-client -T resize
bind -T resize -r j resize-pane -D 10 ';' switch-client -T resize
bind -T resize -r k resize-pane -U 10 ';' switch-client -T resize
bind -T resize -r l resize-pane -R 10 ';' switch-client -T resize
#####################################
## Hooks
#####################################
## Renumber session
## -- Session name will be "$number_of_session + 1"
set-hook -g session-created[100] "run ${_cfgScriptsDir}/hook-renumber-sessions.sh"
set-hook -g session-closed[100] "run ${_cfgScriptsDir}/hook-renumber-sessions.sh"
set-hook -g client-session-changed[100] "run '${_cfgScriptsDir}/hook-last-session.sh save'"
set-hook -g session-closed[101] "run ${_cfgScriptsDir}/hook-last-session.sh"
set-hook -g window-layout-changed[100] 'set-window -F pane-border-status "#{?#{==:#{window_panes},1},off,top}"'
# set-hook -g alert-activity[100] "run ${_cfgScriptsDir}/.sh"
#####################################
## Plugins
#####################################
if-shell "[[ -f ~/.tmux-jump/tmux-jump.tmux ]]" {
set -g @jump-key 'f'
run-shell ~/.tmux-jump/tmux-jump.tmux
}
#####################################
## Archives
#####################################
# ## Extended keys (ctrl+enter, shift+enter, etc)
# # NOTE: IDK if kitty support this inside tmux
# # https://github.com/tmux/tmux/wiki/Modifier-Keys#extended-keys
set -s extended-keys on
# set -as terminal-features ",*:extkeys"
#####################################
## TODO
#####################################
# - Use variable for colors for easy configuration
# Tmux line number
# https://unix.stackexchange.com/a/535010
# bind-key -T copy-mode-vi = split-window -h -p 90 'seq 24 -1 1;sleep 15'\; swap-pane -dU