-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.tmux.conf
502 lines (406 loc) · 16.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
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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# required when launching tmux directly outside a shell session
# https://github.com/tmux/tmux/issues/2541
set-environment -g PATH "/opt/homebrew/bin:/opt/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin"
# https://github.com/orgs/tmux-plugins/repositories?type=all
set -g @plugin 'tmux-plugins/tpm'
# handles `reattach-to-user-namespace`
set -g @plugin 'tmux-plugins/tmux-sensible'
# prefix-F to view keybindings and commands in fzf
set -g @plugin 'sainnhe/tmux-fzf'
# o to open selection in macos
set -g @plugin 'tmux-plugins/tmux-open'
# prefix-u urlview
set -g @plugin 'wfxr/tmux-fzf-url'
# TODO need status bar for this to be useful
# set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
# prefix-y to copy, prefix-shift-y to copy and paste
# outside of copy mode:
set -g @plugin 'tmux-plugins/tmux-yank'
# TODO try instead of vscode/iterm management? https://github.com/jabirali/tmux-tilish
# TODO is this one better? https://github.com/noscript/tmux-mighty-scroll
set -g @plugin 'nhdaly/tmux-better-mouse-mode'
# prefix-f
set -g @plugin 'abhinav/tmux-fastcopy'
# prefix-tab to extract text from pane
set -g @plugin 'laktak/extrakto'
set -g @plugin 'akohlbecker/aw-watcher-tmux'
# TODO another file picker tool https://github.com/tmux-plugins/tmux-fpp/blob/master/fpp.tmux
# TODO copy selection without cancelling isn't set in this config
# remap prefix to C-h. Some people use C-a, but that conflicts with beginning of line for me. C-b is just annoying.
unbind C-b
set-option -g prefix C-h
bind-key C-h send-prefix
# Enter copy mode with prefix-k, much easier
unbind [
bind-key k copy-mode
# enter copy mode without a prefix!
bind -n C-M-k copy-mode
# push fastcopy into macos clipboard
set-option -g @fastcopy-action pbcopy
# easy reload: prefix+r
# https://til.hashrocket.com/posts/d4d3c1fea6-quickly-edit-and-reload-tmux-configuration
bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded"
# https://unix.stackexchange.com/questions/665657/tmux-copy-and-paste-not-working
setw -g mode-keys vi
bind-key -T copy-mode-vi C-a send-keys -X start-of-line
bind-key -T copy-mode-vi C-e send-keys -X end-of-line
# https://stackoverflow.com/questions/10543684/how-do-i-clear-the-scrollback-buffer-in-tmux
# NOTE this is normally bound to create a new window, but we don't do that via tmux
bind -n C-M-l {
if-shell "[ '#{pane_current_command}' = 'zsh' ]" {
# Send Ctrl+Opt+L to the terminal as well
send-keys C-M-l
} {
# TODO detect other shells
send-keys C-c
}
# without this pause, clear-history doesn't clear the current terminal output, and you can still scroll up
run-shell "sleep 0.1"
clear-history
# this messes with ZLE and I'm fine keeping the current buffer on ZSH in place
# send-keys -R
}
# TODO may fix issues with nano https://github.com/mislav/dotfiles/blob/master/tmux.conf#L39C8-L39C19
set -g mouse on
# I'm very nitpicky about the mouse configuration and I've manually configured it below
set -g @yank_with_mouse off
# I don't like the status bar taking up screen real estate
set -g status off
# TODO will this fix my nano problems? I only have them on iterm, so it's prob not the issue
# https://github.com/microsoft/vscode/issues/207545
set -s escape-time 100
# TODO not sure exactly how this works yet, how i can listen to these events?
set -s focus-events on
# TODO https://github.com/abhinav/tmux-fastcopy/issues/160
# set -g destroy-unattached on
# TODO this isn't working! Try -ga, maybe some other tricks?
# https://github.com/impactaky/dotfiles/blob/2913fc22de6df637b1b2cba88215d995f667b64f/tmux/.tmux.conf#L36
# pass VS Code variables from the shell to tmux
set -g update-environment "VSCODE_GIT_ASKPASS_NODE VSCODE_GIT_ASKPASS_EXTRA_ARGS VSCODE_GIT_ASKPASS_MAIN VSCODE_GIT_IPC_HANDLE VSCODE_INJECTION"
# blue is harder to read for me when searching, switch to yellow
# TODO mode-style for iterm
set -g copy-mode-match-style bg=yellow,fg=black
# makes scrolling seem more macos-like
set -g @scroll-speed-num-lines-per-scroll 3
# allows less and other pagers to use the scroll wheel!
set -g @emulate-scroll-for-no-mouse-alternate-buffer on
# expand tmux-fzf plugin to full screen
TMUX_FZF_OPTIONS="-p -w 100% -h 100% -m"
TMUX_FZF_ORDER="command|keybinding|copy-mode|session|window|pane|clipboard|process"
# make colors inside tmux look the same as outside of tmux
# https://unix.stackexchange.com/questions/348771/why-do-vim-colors-look-different-inside-and-outside-of-tmux
set -g default-terminal "xterm-256color"
set-option -ga terminal-overrides ",xterm-256color:Tc"
# Enable CSI u, this makes iterm play better with tmux
# https://github.com/tmux/tmux/wiki/Modifier-Keys#extended-keys
set -s extended-keys on
set -as terminal-features 'xterm*:extkeys'
# TODO https://github.com/abhinav/tmux-fastcopy/issues/155 jump to selection instead of copying
# modify file regex to include line and column numbers
set-option -g @fastcopy-regex-path "(?:[\\w\\-\\.]+|~)?(?:/[\\w\\-\\.@]+){2,}(?:\\:\\d+)?(?:\\:\\d+)?\\b"
set-option -g @fastcopy-regex-stacktrace-path "(?:[\\w\\-\\.@/]+){2,}(?:\\:\\d+)(?:\\:\\d+)?\\b"
# same regex as `regex-path`, but without escape chars
# TODO this matches against https:// too.. `rg --no-filename --no-column --no-line-number --color=never -oP '(?!://)(\~/|./|/)([a-zA-Z0-9_\-\.@/-]+/){2,}[a-zA-Z0-9_\-\.@]+'`
# set -g @fzf-url-extra-filter 'grep -oE "(\~/|./|/)([a-zA-Z0-9_\-\.@/-]+/){2,}[a-zA-Z0-9_\-\.@]+"'
set -g @fzf-url-extra-filter '/opt/homebrew/bin/rg --no-filename --no-column --no-line-number --color=never -oP "(^https://|^(~/|./|/))([a-zA-Z0-9_./@-]+/){2,}[a-zA-Z0-9_./@-]+"'
# open file in editor on shift-{letter}
# default action is copy to clipboard
# TODO did we try relative paths here? can we add this to fastcopy?
# TODO https://github.com/abhinav/tmux-fastcopy/issues/174
set-option -g @fastcopy-shift-action '/Users/mike/.open-file-path.sh {}'
set-option -g @open-editor '/Users/mike/.open-file-path.sh'
# TODO custom extraction patterns https://github.com/laktak/extrakto#custom-filters
set -g @extrakto_editor "~/.open-file-path.sh"
set -g @extrakto_filter_order "all line"
set -g @extrakto_grab_area "recent"
######################################################
#
# - Use pbpcopy for all default copy bindings
# - Trim trailing newlines from EOL copy & more
#
######################################################
# append selection to clipboard
bind-key -T copy-mode-vi A send-keys -X append-selection-and-cancel pbcopy
# copy selection without cancelling copy mode
bind-key -T copy-mode-vi c send-keys -X copy-selection pbcopy
# for `t` and `T` your cursor position matters, only content after cursor will be processed
# copy to EOL and trim trailing newline, but not leading/trailing whitespace
bind-key -T copy-mode-vi t send-keys -X copy-pipe-end-of-line-and-cancel "tr -d '\\n' | pbcopy"
# copy to EOL and trim trailing newline and trailing/leading whitespace
bind-key -T copy-mode-vi T {
send -X copy-pipe-end-of-line-and-cancel "tr -d '\\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | pbcopy"
}
# `w` is bound to next-word by default
# copy word, trim whitespace
bind-key -T copy-mode-vi C-w {
send -X begin-selection
# Continue the current selection to the end of the word
# https://github.com/tmux/tmux/blob/b77778072052c14d1450d2eb89542f2493121f84/window-copy.c#L5326
send -X next-word-end
# trim leading + trailing whitespace
send -X copy-pipe-and-cancel "sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | pbcopy"
}
# TODO this doesn't seem to work properly :/
# copy selection (must have a selection) to clipboard without canceling anything
bind-key -T copy-mode-vi Y send-keys -X copy-selection-no-clear
# rebind Enter to copy line; use y to copy selection
bind-key -T copy-mode-vi Enter {
send -X clear-selection
# get to the start of the physical line
send -X start-of-line
send -X start-of-line
send -X begin-selection
# end of physical line
send -X end-of-line
send -X end-of-line
# trim trailing newline from selection
send -X copy-pipe-and-cancel "tr -d '\\n' | pbcopy"
}
###########################
# Copy Mode navigation
# helpful shortcuts for jumping to content in the buffer very quickly
###########################
# easily jump to prompt starts
# https://unix.stackexchange.com/questions/226731/jump-to-last-prompt-in-terminal-or-tmux
bind-key -T copy-mode-vi b {
send-keys -X start-of-line
send-keys -X search-backward "❯"
}
# easily jump to jest errors, j for jest
bind-key -T copy-mode-vi j {
send-keys -X start-of-line
send-keys -X search-backward " ● "
}
# https://ianthehenry.com/posts/tmux-copy-last-command/
# select the output of the last command
# can be used multiple times
bind -n S-M-Up {
# This just “resets” our state so that we’re ready to copy and so that we have no selection active. Pretty simple.
copy-mode
send -X clear-selection
# This puts our cursor at the start of the current physical line
send -X start-of-line
send -X start-of-line
# And this puts our cursor at the beginning of the physical line just above us
send -X cursor-up
send -X start-of-line
send -X start-of-line
# TODO this is broken with recent prompt changes
# checks “is our cursor now on a line that contains a prompt” after moving
# the previous cursor up a line. This occurs on the second trigger of this command
# https://github.com/iloveitaly/pure/commit/28f22630e6ab05503014e33b06d0ebc9d070e212
if -F "#{m:*❯\u00A0*,#{copy_cursor_line}}" {
send -X cursor-up
}
# skips the git status line
send -X cursor-up
# begin selection at the end of the last prompt input
send -X end-of-line
send -X end-of-line
send -X begin-selection
# jump to the next line after the previous prompt
send -X search-backward-text "❯\u00A0"
send -X end-of-line
send -X end-of-line
send -X cursor-right
# do not `stop-selection` here to retain selection to allow for adjustmnet
}
##############################################################
#
# Fast Searching
# similar to copycat, but using the native search so it's fast
# https://github.com/tmux-plugins/tmux-copycat/tree/master
#
##############################################################
# `/` for quick, interactive searches
bind-key / command-prompt -i -I "#{pane_search_string}" -T search -p "search" {
copy-mode -e
send-keys -X search-backward-incremental "%%"
}
# TODO file search https://github.com/tmux-plugins/tmux-copycat/issues/148
# bind-key f {
# send-keys -X search-backward '[a-zA-Z0-9_./-@]+$'
# }
# TODO add url, file, git sha, etc searches; pull from copycat
###########################
# iTerm rebindings
# In iterm when CSI U mode (extended key mode) is enabled tmux sees M-Left & M-Right arrow keys directly, unlike xterm.js
# or alacritty where \ef & \eb are reported by opt+{right,left} arrow keys. The raw codes in CSI U mode are "\e[1;3C" "\e[1;3D"
# This fixes M-{Arrow} word navigation for me. Weirdly enough, iTerm only does this in a tmux session: not in zsh, bash, etc (although these are not consistent either).
# In copy mode, we want to send specific commands, but in normal mode we want to pass the correct key bindings down to zsh.
###########################
bind -n M-Right send-keys "\ef"
bind -n M-Left send-keys "\eb"
bind -T copy-mode-vi M-Right send-keys -X next-word
bind -T copy-mode-vi M-Left send-keys -X previous-word
###########################
# less-style page up/down
###########################
# this is how `less` does it, and it feels nice
bind-key -T copy-mode-vi u send-keys -X page-up
bind-key -T copy-mode-vi d send-keys -X page-down
# 3x scrolling with shift
bind-key -T copy-mode-vi U send-keys -X halfpage-up \; send-keys -X halfpage-up\; send-keys -X halfpage-up
bind-key -T copy-mode-vi D send-keys -X halfpage-down \; send-keys -X halfpage-down\; send-keys -X halfpage-down
###########################
# option-{Arrow} word navigation
###########################
bind-key -T copy-mode-vi M-f send-keys -X next-word
bind-key -T copy-mode-vi M-b send-keys -X previous-word
###########################
# Keyboard Based Copy Mode Navigation
# allow Shift-{Arrows} to be used to start selection AND mutate selection, like macos
###########################
bind-key -n S-Right {
select-pane
copy-mode
if-shell -F '#{selection_present}' {
send-keys -X cursor-right
} {
send-keys -X begin-selection
send-keys -X cursor-right
}
}
bind-key -n S-Left {
select-pane
copy-mode
if-shell -F '#{selection_present}' {
send-keys -X cursor-left
} {
send-keys -X begin-selection
send-keys -X cursor-left
}
}
bind-key -n S-M-Right {
select-pane
copy-mode
if-shell -F '#{selection_present}' {
send-keys -X next-word
} {
send-keys -X begin-selection
send-keys -X next-word
}
}
bind-key -n S-M-Left {
select-pane
copy-mode
if-shell -F '#{selection_present}' {
send-keys -X previous-word
} {
send-keys -X begin-selection
send-keys -X previous-word
}
}
bind-key -T copy-mode-vi 'S-Down' {
if-shell -F '#{selection_present}' {
send-keys -X cursor-down
} {
send-keys -X begin-selection
send-keys -X cursor-down
}
}
bind-key -T copy-mode-vi 'S-Up' {
if-shell -F '#{selection_present}' {
send-keys -X cursor-up
} {
send-keys -X begin-selection
send-keys -X cursor-up
}
}
bind-key -T copy-mode-vi 'S-Right' {
if-shell -F '#{selection_present}' {
send-keys -X cursor-right
} {
send-keys -X begin-selection
send-keys -X cursor-right
}
}
bind-key -T copy-mode-vi 'S-Left' {
if-shell -F '#{selection_present}' {
send-keys -X cursor-left
} {
send-keys -X begin-selection
send-keys -X cursor-left
}
}
bind-key -T copy-mode-vi S-M-Left {
if-shell -F '#{selection_present}' {
send-keys -X previous-word
} {
send-keys -X begin-selection
send-keys -X previous-word
}
}
bind-key -T copy-mode-vi S-M-Right {
if-shell -F '#{selection_present}' {
send-keys -X next-word
} {
send-keys -X begin-selection
send-keys -X next-word
}
}
# this patch fix errors
if "test ! -d ~/.tmux/plugins/tpm" \
"run 'git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm && ~/.tmux/plugins/tpm/bin/install_plugins'"
run '~/.tmux/plugins/tpm/tpm'
# TODO never got this working, some bug in the macos integration
# set-option -g @plugin 'b0o/tmux-autoreload'
###########################
# macos-style mouse selection
# must run after tpm
###########################
# don't cancel selection when double click ends
# works in copy mode too
bind-key -n DoubleClick1Pane {
select-pane
copy-mode -M
send-keys -X select-word
}
# once we are in copy mode, single click to start new selection
bind -T copy-mode-vi MouseDown1Pane {
select-pane
send-keys -X clear-selection
}
# triple click to copy entire line
bind-key -n TripleClick1Pane {
select-pane
# -M is only valid in mouse mode
copy-mode -M
send-keys -X select-line
send-keys -X copy-pipe-end-of-line-and-cancel "tr -d '\\n' | pbcopy"
# without the sleep, the message dissapears
run-shell "sleep 0.1"
display-message "Copied line to clipboard"
}
# TODO create another binding which copies the last output, trims trailing newlines, and copies to clipboard
# TODO should replace the existing yank script
# copy line in prompt, modified from tmux-yank
bind p {
# go to beginning of line, this respects whatever prompt header (zsh, ipy, etc) is present
send-key 'C-a'
run-shell "sleep 0.01"
select-pane
copy-mode
send-keys -X begin-selection
send-keys -X end-of-line
# TODO do we need to do end-of-line twice?
send-keys -X copy-pipe-and-cancel "tr -d '\\n' | pbcopy"
# now jump to the end of the line since we are out of copy mode
send-key 'C-e'
# without the sleep, the message disappears
run-shell "sleep 0.1"
display-message "Copied prompt line to clipboard"
}
# do not cancel selection when dragging ends
# TODO document exactly what is binding these actions
unbind -T copy-mode-vi MouseDragEnd1Pane
unbind -T copy-mode MouseDragEnd1Pane
unbind -T copy-mode-vi DoubleClick1Pane
unbind -T copy-mode DoubleClick1Pane
unbind -T copy-mode-vi TripleClick1Pane
unbind -T copy-mode TripleClick1Pane
# TODO unbind rightclick
# this is at the bottom because it messes with syntax highlighting in vs code
# align word separators with a more standard terminal
# https://github.com/tmux/tmux/issues/3528
set-option -g word-separators " ()[]{}',:;\""