-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmux.conf
executable file
·479 lines (398 loc) · 18.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
# --------------------------------------------------------- #
# ________ _____ ___ __ __________ _ ________ #
# /_ __/ |/ / / / / |/ / / ____/ __ \/ | / / ____/ #
# / / / /|_/ / / / /| / / / / / / / |/ / /_ #
# / / / / / / /_/ // | / /___/ /_/ / /| / __/ #
# /_/ /_/ /_/\____//_/|_| \____/\____/_/ |_/_/ #
# --------------------------------------------------------- #
# Creator: Eb
# Date created: Mon Jan 17 10:44:52 AM +03 2022
# Last update: 2024-07-05
# Version: 2.0
# --------------------------------------------------------- #
# Description:
#
# My TMUX configs
# --------------------------------------------------------- #
# TODO:
# - update servers with the tpm plugin manager
# - install zoxide on servers (ubuntu)
# - remove unused scripts from my servers
## ----------------------------------------------------------------------------
## GENERAL SETTINGS -----------------------------------------------------------
## ----------------------------------------------------------------------------
set -g history-limit 100000 # increase history size
set -s escape-time 0 # Faster command sequences
set -sg repeat-time 600 # Increase repeat timeout
set -g monitor-activity on
set -g mouse on # enable mouse support in tmux
set -g base-index 1 # Start window numbering at 1 instead of 0
set-window-option -g pane-base-index 1 # Start pane numbering at 1 instead of 0
set-option -g status-keys "vi" # vim style keybinding when using command mode
set -s focus-events on # allows focus events to be detected (for example when using vim)
set -g display-panes-time 800
set -g display-time 2000
set -g status-interval 1
set -g allow-rename on
set-window-option -g window-status-format "#W"
set-window-option -g window-status-current-format "#W"
set-option -g detach-on-destroy off # behaviour when killing a session
# NOTE: allow OSC52 to set the clipboard | https://github.com/laktak/extrakto/wiki/Remote-Copy-via-OSC52
# the copy to cliboard function of extrakto does not work for some reason both on local and remote
# https://github.com/tmux/tmux/wiki/Clipboard?utm_source=pocket_mylist
set -g set-clipboard on
# NOTE: the below settings are for displaying proper colors in tmux
# underscore colours - needs tmux-3.0
set -g default-terminal "tmux-256color"
# undercurl support
set -as terminal-overrides ',*:Smulx=\E[4::%p1%dm'
# underscore colours - needs tmux-3.0
set -as terminal-overrides ',*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m'
# not sure about the below ones need to add references
set -ga terminal-overrides ",*256col*:Tc"
set -as terminal-overrides ',xterm*:sitm=\E[3m'
# Change color of focused and unfocused panes, it helps me easily identify where
# my cursor is
# Make sure these colors also match your neovim autocmd if you change them
# set-hook -g pane-focus-in 'select-pane -P "bg=,fg=default"'
# set-hook -g pane-focus-out 'select-pane -P "bg=,fg=default"'
# NOTE: fix for tmux and SSH forwarding agent
set-environment -g 'SSH_AUTH_SOCK' ~/.ssh/ssh_auth_sock
# NOTE: required for YAZI
set -g allow-passthrough all
set -ga update-environment TERM
set -ga update-environment TERM_PROGRAM
## ----------------------------------------------------------------------------
## KEYBINDS -------------------------------------------------------------------
## ----------------------------------------------------------------------------
# NOTE: -n means do not use any prefix
# NOTE: Remap prefix key to ctrl+a
unbind C-b
set -g prefix C-a
# NOTE: Send prefix to a nested tmux session on a remote server.
bind-key -n C-b send-prefix
## PANES
## ----------------------------------------------------------------------------
# NOTE: unbind default keybinds
# Splits (v and h are not bound by default, but we never know in the next versions)
unbind % # DEFAULT: Split vertically
unbind '"' # DEFAULT: Split horizontally
unbind v
unbind h
unbind z
bind v 'split-window -h -c "#{pane_current_path}"'
bind h 'split-window -v -c "#{pane_current_path}"'
# Movement
bind -n C-h select-pane -L
bind -n C-j select-pane -D
bind -n C-k select-pane -U
bind -n C-l select-pane -R
# Resize panes
bind-key -n C-Up resize-pane -U 5
bind-key -n C-Down resize-pane -D 5
bind-key -n C-Left resize-pane -L 5
bind-key -n C-Right resize-pane -R 5
# Swap panes
bind > swap-pane -D
bind < swap-pane -U
bind-key B break-pane -d
bind-key x kill-pane # kills pane and skips the y/n prompt
# NOTE: Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
# to get this to work vim-tmux-navigator plugin for vim must be installed and configured
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
bind -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
bind -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
bind -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
bind -n C-\\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
# NOTE: mayab disable this
# TODO: remove from my ansible config
# unbind w # DEFAULT: change current window interactively
# bind w run-shell tmlw
## WINDOWS
## ----------------------------------------------------------------------------
# NOTE: unbind default keybinds
unbind n # DEFAULT KEY: Move to next window
unbind c # DEFAULT: create new window
# Create new window and prompt to name the window
bind-key n command-prompt -p "Name of new window: " "new-window -c '#{pane_current_path}' -n '%%'"
# Rename current window
bind-key c command-prompt -I "#{window_name}" "rename-window '%%'"
# Rename current session
bind C command-prompt -I "#{session_name}" "rename-session '%%'"
# Quick navigation between windows
bind -n M-j previous-window
bind -n M-k next-window
# Kill window
bind X kill-window
## Custom
## ----------------------------------------------------------------------------
# NOTE: unbind default keybinds
unbind r
unbind f # Default: find-window
unbind E
# Keybinding to process the error message
bind-key E split-window -h "bash ~/.local/bin/goto-error"
bind j "switch-client -t'{marked}'" # jump to a marked pane
# source the tmux file
bind r run 'tmux source-file ~/.config/tmux/tmux.conf \; display "TMUX Config Reloaded!"'
bind-key T 'split-window -h htop' # open htop in a split pane
bind-key C-v 'run-shell "~/.local/bin/tmux-nvim"' # open nvim in a new pane
# NOTE: lists all text copied to the tmux buffer in copy mode
bind b 'list-buffers'
bind p 'paste-buffer -p'
bind P "choose-buffer"
# NOTE: clear screen
bind C-l send-keys 'C-l'
# NOTE: search windows in current session
# SOURCE: https://x.com/Adib_Hanna/status/1858537967339315562/photo/1
bind C-f display-popup -E "\
tmux list-windows -F '#{window_index} #{window_name}' |\
sed '/^$/d' |\
fzf --no-border --reverse --header jump-to-window --prompt=' '|\
cut -d ' ' -f 1 |\
xargs tmux select-window -t"
# HARPOON
# https://github.com/Chaitanyabsprip/tmux-harpoon
# TODO: look up the harpoon documentation for more ideas and possibly post an issue on the repo for the remove command
bind -n M-a run "[ -x $(command -v notify-send) ] && notify-send -t 1000 '' 'Added tmux mark' || true; harpoon -a" # add tmux session to harpoon
bind -n M-t run "harpoon -l" # list tracked sessions with fzf
bind -n M-r run "[ -x $(command -v notify-send) ] && notify-send -t 1000 '' 'Deleted tmux mark' || true; harpoon -d tmux display-message -p '#S'" # delete focused session from harpoon
bind -n M-e run "harpoon -e" # edit harpoon list
bind -n M-1 run "harpoon -s 1" # jump to bookmark at index 1
bind -n M-2 run "harpoon -s 2" # jump to bookmark at index 2
bind -n M-3 run "harpoon -s 3" # jump to bookmark at index 3
bind -n M-4 run "harpoon -s 4" # jump to bookmark at index 4
bind 1 run "harpoon -r 1 && '' 'Update index 1 with current session'" # replace entry at index 1 with current session
bind 2 run "harpoon -r 2 && '' 'Update index 2 with current session'" # replace entry at index 2 with current session
bind 3 run "harpoon -r 3 && '' 'Update index 3 with current session'" # replace entry at index 3 with current session
bind 4 run "harpoon -r 4 && '' 'Update index 4 with current session'" # replace entry at index 4 with current session
# Sesh
# https://github.com/joshmedeski/sesh
bind-key f run-shell '~/.config/tmux/tmux-scripts/tmux-sesh'
# NOTE: https://github.com/joshmedeski/sesh?tab=readme-ov-file#last
unbind L
bind -N "last-session (via sesh) " L run-shell "sesh last"
# NOTE: https://github.com/joshmedeski/sesh?tab=readme-ov-file#connect-to-root
# bind-key "F" display-popup -E -w 40% "sesh connect \"$(
# sesh list -i -H | gum filter --value \"$(sesh root)\" --limit 1 --fuzzy --no-sort --placeholder 'Pick a sesh' --prompt='⚡'readme
# )\""
## Copy Mode
## ----------------------------------------------------------------------------
# copy mode in tmux, use VIM keys in tmux
set-window-option -g mode-keys vi
#settings to copy contents to system clipboard instead of tmux clipboard
unbind -T copy-mode-vi Space; #Default for begin-selection
unbind -T copy-mode-vi Enter; #Default for copy-selection
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xsel --clipboard"
# new binding to enter vi-mode
unbind [
bind e copy-mode
# # Copy selection on drag end event, but do not cancel copy mode and do not clear selection
# # clear select on subsequence mouse click
# bind -T copy-mode-vi MouseDragEnd1Pane \
# send-keys -X copy-pipe "$yank"
# bind -T copy-mode-vi MouseDown1Pane select-pane \;\
# send-keys -X clear-selection
## ----------------------------------------------------------------------------
## THEME ----------------------------------------------------------------------
## ----------------------------------------------------------------------------
# SOURCE: https://github.com/arunh/tmux-gruvbox-material
# Original theme sourced from here
# Colors:
color_bg='#282828'
color_bg2='#a89984'
color_bg3='#3c3836'
color_bg4='#5b534d'
color_bg5='#32302f'
color_bg6='#1D2021'
color_fg='#ddc7a1'
color_fg2='#a89984'
color_red='#ea6962'
color_orange='#e78a4e'
color_yellow='#d8a657'
color_green='#a9b665'
color_aqua='#89b482'
color_bright_green='#89b482'
color_blue='#7daea3'
color_purple='#d3869b'
# Theme contract variables
dark_bg="$color_bg"
dark_bg2="$color_bg6"
dark_bg3="$color_bg3"
dark_bg4="$color_bg4"
light_bg2="$color_bg2"
text_on_light_bg="$color_bg"
text_on_dark_bg="$color_fg"
text_on_dark_bg2="$color_fg2"
active_window_bg="$color_aqua"
active_window_fg_focus="$color_orange"
color_status_text="$dark_bg3"
color_window_off_status_bg="$dark_bg3"
# General settings for bar
set -g status "on"
set -g status-justify "left"
set -g status-position "bottom"
set -g status-right-length "100"
set -g status-left-length "100"
setw -g window-status-separator ""
# Status line style
set -g status-style "fg=$text_on_dark_bg2,bg=$dark_bg2"
# Command line style
set -g message-style "fg=$text_on_dark_bg2,bg=$dark_bg2"
# Pane
set -g pane-active-border-style "fg=$color_blue"
set -g pane-border-style "fg=$color_bg4"
# TODO:
# experiment with window-style & window-active-style bg colors
# https://youtu.be/-l9fXyqgh1Y
# Window status
setw -g window-status-activity-style "none"
setw -g window-status-format " #I:#W "
setw -g window-status-current-format " #I:#W "
# set -g window-status-current-style "fg=$text_on_light_bg,bg=$active_window_bg"
set -g window-status-current-style "fg=$color_blue,bg=$dark_bg2, bold"
# Status left
set -g status-left-style "none"
set -g status-left "#{?client_prefix,#[bg=$color_green]#[fg=$text_on_light_bg],} #S "
# Status Right
set -g status-right-style "none"
# right_column_1="#[fg=$text_on_dark_bg,bg=$dark_bg2, nobold] #(gitmux -cfg $HOME/.config/tmux/.gitmux.conf #{pane_current_path})"
right_column_3="#[fg=$color_aqua,bg=$dark_bg2, nobold] #h #(tmux-ip)"
right_column_2="#[fg=$text_on_dark_bg,bg=$dark_bg2, nobold] #(tmux-battery)"
right_column_4="#[fg=$text_on_dark_bg2,bg=$dark_bg2, nobold] #(tmux-date)"
right_column_5="#[fg=$color_aqua,bg=$dark_bg2, nobold] #(tmux-diskfree)"
set -g status-right " ${right_column_1} ${right_column_2} ${right_column_4}${right_column_3} "
# ------------------------------------ #
# Nesting Local & Remote tmux sessions #
# ------------------------------------ #
# NOTE: below tasks are completed but keeping them here for future reference
# SOUCE: https://github.com/samoshkin/tmux-config/tree/master#nested-tmux-sessions
# - [x] The remote conf is working as intended.
# - [x] The f12 toggle to swap between local and remote
# - [x] need to work on swapping the colors based on whether workign on remote or local
# - [x] apart from colors, mayb add another indicator as well that the status bar is turned off
# Session is considered to be remote when we ssh into host
if-shell 'test -n "$SSH_CLIENT"' \
'source-file ~/.config/tmux/tmux.remote.conf'
# Toggle for switching control between local and remote, this section also has visual changes when the F12 key is pressed.
# By default it also hides the status bar. To change this behaviour comment out the <set-option status>
bind -T root F12 \
set prefix None \;\
set key-table off \;\
set status-style "fg=$color_status_text, bg=$color_window_off_status_bg"\;\
set window-status-current-format "#[fg=$color_red, bold] OFF"\;\
set window-status-current-style "fg=$color_status_text, bg=$color_window_off_status_bg"\;\
set status-left "#[bg=$color_window_off_status_bg]"\;\
set status-right "${right_column_4}"\;\
set-option status\;\
if -F '#{pane_in_mode}' 'send-keys -X cancel' \;\
bind -T off F12 \
set -u prefix \;\
set -u key-table \;\
set -u status-style \;\
set -u window-status-current-format\;\
set -u window-status-current-style\;\
set -u status-left\;\
set -u status-right\;\
set-option -u status\;\
# ------------ #
# Tmux Plugins #
# ------------ #
# TMUX Resurrect
set -g @plugin 'tmux-plugins/tmux-resurrect'
# NOTE: restore vim and neovim sessions
# Source - https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_vim_and_neovim_sessions.md
set -g @resurrect-strategy-nvim 'session'
# NOTE: restore pane contents
set -g @resurrect-capture-pane-contents 'on'
set -g @resurect-processes 'nvim zsh htop'
# NOTE:
# SOURCE: https://discourse.nixos.org/t/how-to-get-tmux-resurrect-to-restore-neovim-sessions/30819
# resurrecting nvim sessions does not work without the below:
resurrect_dir="$HOME/.tmux/tmux-resurrect-sessions"
set -g @resurrect-dir $resurrect_dir
set -g @resurrect-hook-post-save-all 'target=$(readlink -f $resurrect_dir/last); sed "s| --cmd .*-vim-pack-dir||g; s|/etc/profiles/per-user/$USER/bin/||g; s|/home/$USER/.nix-profile/bin/||g" $target | sponge $target'
# TMUX Continuum
# https://github.com/tmux-plugins/tmux-continuum
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @continuum-save-interval '15'
# t-smart-tmux-session-manager
# https://github.com/joshmedeski/t-smart-tmux-session-manager
# set -g @plugin 'joshmedeski/t-smart-tmux-session-manager'
# set -g @t-fzf-prompt ' '
# set -g @t-bind 'none' # unbind default keybind for tmux session manager
# set -g @t-bind 'f'
# # https://github.com/joshmedeski/t-smart-tmux-session-manager#change-default-fzf-results
# set -g @t-fzf-default-results 'sessions' # make session view default
# # https://github.com/joshmedeski/t-smart-tmux-session-manager#custom-find-command
# set -g @t-fzf-find-binding \
# 'ctrl-f:change-prompt( )+reload(fd \
# --hidden \
# --max-depth=5 \
# --type=d \
# --exclude='.git/' --exclude='node_modules' . /home/)'
# TMUX-thumbs
# https://github.com/fcsonline/tmux-thumbs
set -g @plugin 'fcsonline/tmux-thumbs'
run-shell ~/.tmux/plugins/tmux-thumbs/tmux-thumbs.tmux
set -g @thumbs-alphabet qwerty
# TMUX-FZF-URL
# https://github.com/wfxr/tmux-fzf-url
set -g @plugin 'wfxr/tmux-fzf-url'
set -g @fzf-url-bind 'o'
# tmux-transient-status
# https://github.com/TheSast/tmux-transient-status
# NOTE: This tmux tpm plugin makes your status bar appear only after the <prefix>
# key is pressed (and for a small amout of time thereafter).
# TODO:
# - [ ] add this plugin to my servers
# - [ ] add this plugin to my desktop
set -g @plugin 'thesast/tmux-transient-status'
set -g @transient-status-delay '0'
set -g @transient-status-stall '0'
# tmux-power-zoom
# https://github.com/jaclu/tmux-power-zoom
# NOTE: Zoom pane to separate window, and un-zoom back into the original location.
# TODO:
# - [ ] add this plugin to my servers
# - [ ] add this plugin to my desktop
set -g @plugin 'jaclu/tmux-power-zoom'
set -g @power_zoom_trigger 'z'
# tmux-sidebar
# https://github.com/tmux-plugins/tmux-sidebar
# NOTE: does one thing: it opens a tree directory listing for the current path.
# It's fast, convenient and works great with vim.
# TODO:
# - [ ] add this plugin to my servers
# - [ ] add this plugin to my desktop
set -g @plugin 'tmux-plugins/tmux-sidebar'
set -g @sidebar-tree-command 'tree -C'
# TPM Plugin manager
# NOTE: Set this to change install directory for plugins
set-environment -g TMUX_PLUGIN_MANAGER_PATH '~/.tmux/plugins/'
# automatic tpm installation
if "test ! -d ~/.tmux/plugins/tpm" \
"run 'git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm && ~/.tmux/plugins/tpm/bin/install_plugins'"
# NOTE: This must be at the bottom of the script to work
run '~/.tmux/plugins/tpm/tpm'
# TODO: check if the below is in my ansible config and remove if needed
# NOTE: mayb disable this
# switch TMUX session
# bind-key a split-window -h "~/scripts/bash_scripts/tmux_scripts/tmux-fzf-switch.sh"
# bind-key a run-shell "~/.local/bin/tmss"
# TODO: check if the below is in my ansible config and remove if needed
# NOTE: mayb disable this
# Kill a tmux session
# bind-key C-k run-shell "~/.local/bin/tmks"
# TODO: check if the below is in my ansible config and remove if needed
# List current tmux sessions
# bind-key C-l run-shell "~/.local/bin/tmux-quick-switch"
# TODO: check if the below is in my ansible config and remove if needed
# break out to new TMUX session
# BUG: the run-shell command will not work for some reason, need to look for a fix
# Disabling for now
# bind-key C-b send-keys "tmat && exit" "C-m"