aboutsummaryrefslogtreecommitdiff
path: root/.config/tmux/tmux.conf
blob: 6bd9567391a20a2dfe4565d2667da202b0f1d8aa (plain)
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
#  ████████╗███╗   ███╗██╗   ██╗██╗  ██╗
#  ╚══██╔══╝████╗ ████║██║   ██║╚██╗██╔╝
#     ██║   ██╔████╔██║██║   ██║ ╚███╔╝
#     ██║   ██║╚██╔╝██║██║   ██║ ██╔██╗
#     ██║   ██║ ╚═╝ ██║╚██████╔╝██╔╝ ██╗
#     ╚═╝   ╚═╝     ╚═╝ ╚═════╝ ╚═╝  ╚═╝
#――――――――――――――――――――――――――――――――――――――――――

### Options ###

# Setting the Prefix from Ctrl+b to Ctrl+s
unbind C-b
set -g prefix C-s
#set -g prefix M-Space

# Ensure that we can send Ctrl+s to other apps
bind C-s send-prefix

# Send the prefix to client inside window (nested tmux)
bind-key -n C-a send-prefix

# Disable local tmux keys (nested tmux)
bind -T root F12 \
  set prefix None \;\
  set key-table off \;\
  if -F '#{pane_in_mode}' 'send-keys -X cancel' \;\
  refresh-client -S \;\

bind -T off F12 \
  set -u prefix \;\
  set -u key-table \;\
  refresh-client -S

# Setting the delay between Prefix and Command
set -sg escape-time 10
#set-option -sg escape-time 10

# Reload tmux with <Prefix>r
#bind r source-file ~/.tmux.conf \; display "Reloaded!"
bind r source-file ~/.config/tmux/tmux.conf \; display "Reloaded!"

# Use <Prefix>L to clear terminal
bind -r L send-keys 'C-l'

# Rename current window (Ctrl + A, A)
bind R rename-window '' \; \
        command-prompt -I "#W" "rename-window -- '%%'"

# Mouse
set -g mouse on
#set -g mouse-select-pane on
#set -g mouse-resize-pane on
#set -g mouse-select-window on

# Scrollback
#set -g history-limit 10000

# Sane scrolling
set -g terminal-overrides 'xterm*:smcup@:rmcup@'

# Shift up/down copy-mode without prefix
bind-key -n S-Up copy-mode \; send-key Up
bind-key -n S-Down copy-mode \; send-key Down
bind-key -n Pageup copy-mode \; send-key Pageup
bind-key -n Pagedown copy-mode \; send-key Pagedown
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
#bind -n M-k if-shell "$is_vim" "send-keys Pageup" "copy-mode -u"
bind -n Pageup if-shell "$is_vim" "send-keys Pageup" "copy-mode -u"
bind -n S-Pageup if-shell "$is_vim" "send-keys Pageup" "copy-mode -u"
bind -n S-Pagedown send-keys Pagedown
#bind -n M-j send-keys Pagedown

# Focus events, allow supported requests from applications to passthrough/run in tmux
set-option -g focus-events on

# Update the TERM variable of terminal emulator when creating a new session or attaching a existing session
set -g update-environment 'DISPLAY SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY TERM'


#――――――――――――――――――――――――――――――――――――――――――

### Window Movement/Control ###

# Aggressive resizing, useful when using "grouped sessions" and multi-monitor setup
setw -g aggressive-resize on

# Popup scratch session
#bind -n M-g display-popup -E "tmux new-session -A -s scratch"

# Toggle popup scratch session
bind-key -n M-g if-shell -F '#{==:#{session_name},note}' {
detach-client
} {
display-popup -E "tmux new-session -A -s note"
}

# Non-popup
#bind C-k new-window -n "session-switcher" "\
#    tmux list-sessions -F '#{?session_attached,,#{session_name}}' |\
#    sed '/^$/d' |\
#    fzf --reverse --header jump-to-session --preview 'tmux capture-pane -pt {}'  |\
#    xargs tmux switch-client -t"

# List sessions
bind -n M-f display-popup -E "\
    tmux list-sessions -F '#{?session_attached,,#{session_name}}' |\
    sed '/^$/d' |\
    fzf --reverse --header jump-to-session --preview 'tmux capture-pane -pt {}'  |\
    xargs tmux switch-client -t"

# Quick window select
bind -n M-? list-keys
bind -n M-0 select-window -t :=0
bind -n M-1 select-window -t :=1
bind -n M-2 select-window -t :=2
bind -n M-3 select-window -t :=3
bind -n M-4 select-window -t :=4
bind -n M-5 select-window -t :=5
bind -n M-6 select-window -t :=6
bind -n M-7 select-window -t :=7
bind -n M-8 select-window -t :=8
bind -n M-9 select-window -t :=9


#――――――――――――――――――――――――――――――――――――――――――

### Pane Movement/Control ###

# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
# Navigate across tmux-vim
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"

# {{{ keybinds: select-pane
bind -Tnav h   select-pane -L
bind       h   select-pane -L
bind -Tnav C-h select-pane -L
bind       C-h select-pane -L
bind -Tnav j   select-pane -D
bind       j   select-pane -D
bind -Tnav C-j select-pane -D
bind       C-j select-pane -D
bind -Tnav k   select-pane -U
bind       k   select-pane -U
bind -Tnav C-k select-pane -U
bind       C-k select-pane -U
bind -Tnav l   select-pane -R
bind       l   select-pane -R
bind -Tnav C-l select-pane -R
bind       C-l select-pane -R
# keybinds: select-pane }}}

# {{{ keybinds: split-window
bind -Tnav "\\" split-window -h  -c "#{pane_current_path}" # vertical
bind       "\\" split-window -h  -c "#{pane_current_path}" # vertical
bind -Tnav "|"  split-window -fh -c "#{pane_current_path}" # full vertical
bind       "|"  split-window -fh -c "#{pane_current_path}" # full vertical
bind -Tnav "-"  split-window -v  -c "#{pane_current_path}" # horizontal
bind       "-"  split-window -v  -c "#{pane_current_path}" # horizontal
bind -Tnav "_"  split-window -fv -c "#{pane_current_path}" # full horizontal
bind       "_"  split-window -fv -c "#{pane_current_path}" # full horizontal
# keybinds: split-window }}}

# {{{ keybinds: resize-pane
bind -r -Tnav M-h resize-pane -L 10
bind -r       M-h resize-pane -L 10
bind -r -Tnav M-j resize-pane -D 5
bind -r       M-j resize-pane -D 5
bind -r -Tnav M-k resize-pane -U 5
bind -r       M-k resize-pane -U 5
bind -r -Tnav M-l resize-pane -R 10
bind -r       M-l resize-pane -R 10
# keybinds: resize-pane }}}

# Hide a pane and bring it back with <Prefix>! and <Prefix>@ respectively
bind-key ! break-pane -d -n _hidden_pane
bind-key @ join-pane -s $.0

# Send Pane to another session/window
bind-key = command-prompt -p "send pane to:"  "join-pane -t '%%'"


#――――――――――――――――――――――――――――――――――――――――――

### Copy Mode (Copy/Paste) ###

# Set Vi copy mode, use <prefix>[ to enter copy mode
setw -g mode-keys vi # `<prefix>:list-keys -T copy-mode-vi` to confirm

# Change selection <space> and enter to vi keybinding
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel

# Copy to system clipboard (requires xclip)
if-shell -b 'echo $XDG_SESSION_TYPE | grep -q x11' "\
    bind-key -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard > /dev/null'; \
    bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard > /dev/null'; \
    bind-key C-M-v run 'xclip -out -selection clipboard | tmux load-buffer - ; tmux paste-buffer'"

# Wayland support
if-shell -b 'echo $XDG_SESSION_TYPE | grep -q wayland' "\
    bind-key -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel 'wl-copy'; \
    bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel 'wl-copy'; \
    bind-key C-p run 'wl-paste --no-newline | tmux load-buffer - ; tmux paste-buffer'" "\
    \
    bind-key -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel 'cat - >/dev/clipboard'; \
    bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel 'cat - >/dev/clipboard'; \
    bind-key C-M-v run 'cat /dev/clipboard | tmux load-buffer - ; tmux paste-buffer'"

#

### Colors ###

## Assume external terminal supports the 256 colors palette (when TERM=xterm-256color)
#set -sa terminal-features ",xterm-256color:256"
## Assume external terminal supports RGB colors (when TERM=xterm-256color)
#set -sa terminal-features ",xterm-256color:RGB"
#
## Set TERM for proper colors
#set -g default-terminal "tmux-256color"
set -g default-terminal "xterm-256color"


# Set 256 color terminal
#set-option -sa terminal-overrides ",tmux-256color:Tc"
#set-option -sa terminal-overrides ",xterm*:Tc,alacritty*:Tc"

# Colors for pane borders(default)
setw -g pane-border-style fg=white
setw -g pane-active-border-style fg=green

# Active pane normal, other shaded out
setw -g window-style fg=colour240
setw -g window-active-style fg=white


#

### Status ###

set -g status-position bottom # [top, bottom]
set -g status on
#set -g status-interval 1
set -g status-interval 500
set -g status-style fg=#50fa7b,bg=default

## Left
#set -g status-left ""
set -g status-left-length 60
#set -g status-left "#[fg=#50fa7b,bg=default]#[bg=#50fa7b,fg=black] ❐ #S #[fg=#50fa7b,bg=default]"
set -g status-left "#(cat ~/.vi-mode | awk '/-- NORMAL --/ {print \"#[fg=#39BAE6]#[bg=default]#[bg=#39BAE6,fg=#000000]  ❐ #S  #[fg=#39BAE6,bg=default]\"} /-- INSERT --/ {print \"#[fg=#50fa7b]#[bg=default]#[bg=#50fa7b,fg=#000000]  ❐ #S  #[fg=#50fa7b,bg=default]\"}')"

## Centre
#set -g window-status-current-format "#[bg=default,fg=#50fa7b]#[fg=black,bg=#50fa7b] #I:#W #[bg=default,fg=#50fa7b]"
set -g window-status-current-format "#(cat ~/.vi-mode | awk '/-- NORMAL --/ {print \"#[fg=#39BAE6]#[bg=default]#[fg=#000000,bg=#39BAE6] #I:#W #[bg=default,fg=#39BAE6]\"} /-- INSERT --/ {print \"#[fg=#50fa7b]#[bg=default]#[fg=#000000,bg=#50fa7b] #I:#W #[bg=default,fg=#50fa7b]\"}')"
set -g status-justify absolute-centre

## Right
set-option -g status-right ""
set -g status-right-length 60
#set -g status-right "#[fg=#50fa7b,bg=default] #{?client_prefix,#[reverse] Prefix #[noreverse] ,} #[bg=default,fg=#50fa7b]#[bg=#50fa7b,fg=black] %H:%M #[bg=default,fg=#50fa7b]"
local_keys_off="#[fg=#50fa7b,bg=default]#([ $(tmux show-option -qv key-table) = 'off' ] && echo 'OFF')#[default]"
set -g status-right "$local_keys_off #(cat ~/.vi-mode | awk '/-- NORMAL --/ {print \"#[fg=#50fa7b,bg=default] #{?client_prefix,#[reverse] Prefix #[noreverse] ,} #[fg=#39BAE6]#[bg=default]#[bg=#39BAE6,fg=#000000]  %H:%M  #[bg=default,fg=#39BAE6]\"} /-- INSERT --/ {print \"#[fg=#39BAE6,bg=default] #{?client_prefix,#[reverse] Prefix #[noreverse] ,} #[fg=#50fa7b]#[bg=default]#[bg=#50fa7b,fg=#000000]  %H:%M  #[bg=default,fg=#50fa7b]\"}')"

#set -g status-right "#[fg=white,bg=black]#(cat ~/.vi-mode)"
#set -g status-right "#[fg=white,bg=black]#(cat ~/.vi-mode | awk '/-- NORMAL --/ {print \"#[fg=blue]#[bg=black]-- NORMAL --\"} /-- INSERT --/ {print \"#[fg=green]#[bg=black]-- INSERT --\"}')"

## Reload Status with IP addr, Cpu, Mem and Date
bind a run-shell ~/.config/tmux/tmux-toggle-option.sh

## Reload Config/Status silently
bind b source-file ~/.config/tmux/tmux.conf

set-option -g default-shell "/usr/bin/zsh"


#――――――――――――――――――――――――――――――――――――――――――

### Plugin Install ###

set -g @plugin "tmux-plugins/tpm"
#set -g @plugin "tmux-plugins/tmux-sensible"
set -g @plugin "tmux-plugins/tmux-resurrect"
set -g @plugin "tmux-plugins/tmux-continuum"
set -g @plugin "christoomey/vim-tmux-navigator"
#set -g @plugin "tmux-plugins/tmux-yank"
#set -g @plugin 'srdusr/tmux-vi-mode'
#set -g @plugin 'vi-mode ~/.config/tmux/plugins/vi-mode.sh'


#――――――――――――――――――――――――――――――――――――――――――

### Plugins Settings ###

# Plugin to save and restore tmux sessions after restart
# * Save with: <Prefix> + Ctrl-s
# * Restore with: <Prefix> + Ctlr-r
# Change default save and restore keybindings
  set -g @resurrect-save "W" # <Prefix> + W
  set -g @resurrect-restore "E" # <Prefix> + E

# Restore vim and nvim sessions as well
# For vim:
  set -g @resurrect-strategy-vim "session"
# For neovim:
  set -g @resurrect-strategy-nvim "session"

# Automatic restore
  #set -g @continuum-restore "on"
  #set -g @continuum-boot "on"

# Restore Panes
  set -g @resurrect-capture-pane-contents "on"

# This is a hook for tmux-resurrect which tells it to kill session 0 before restoring the panels
  set -g @resurrect-hook-pre-restore-pane-processes "tmux switch-client -n && tmux kill-session -t=0"

# Plugin uninstall
  # Delete or comment out the plugin in .tmux.conf.
  # Press <prefix> + alt + u to remove the plugin.

# TMUX plugin manager (keep at the bottom of tmux.conf)
  #run "~/.config/tmux/plugins/tpm/tpm"
  if "test ! -d ~/.config/tmux/plugins/tpm" \
   "run 'git clone https://github.com/tmux-plugins/tpm ~/.config/tmux/plugins/tpm && ~/.config/tmux/plugins/tpm/bin/install_plugins'"
run -b "~/.config/tmux/plugins/tpm/tpm"
# Load the vi-mode plugin

#run-shell '~/.config/tmux/plugins/tmux-vi-mode/tmux-vi-mode.tmux'
#run-shell '~/.config/tmux/vi-mode'
# Load the vi-mode plugin
#run '~/.config/tmux/plugins/tpm/plugins/tmux-vi-mode/tmux-vi-mode.tmux'
#――――――――――――――――――――――――――――――――――――――――――