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

### 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

# 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>Ctrl+l to clear terminal
bind C-l send-keys 'C-l'

# Scrollback 
#set -g history-limit 10000

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

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

# Aggresive resizing, useful when using "grouped sessions" and multi-monitor setup
setw -g aggressive-resize 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'

## 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},scratch}' {
detach-client
} {
display-popup -E "tmux new-session -A -s scratch"
}

# 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"

# Popup
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-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
bind -n M-0 select-window -t :=0


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

### Pane Movement/Control ###

# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?)(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h'  'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j'  'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k'  'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l'  'select-pane -R'
tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\'  'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\'  'select-pane -l'"

# Copy Mode vi-directional keys
bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l

# Change horizontal split <Prefix>% and Vertical split <Prefix>" to <Prefix>h and <Prefix>v respectively and change current working directory
bind v split-window -h -c "#{pane_current_path}"
bind h split-window -v -c "#{pane_current_path}"

# Pane resizing, <Prefix> then shift + vi-directional keys, default is D,U,L,R
bind -r H resize-pane -L 20
bind -r J resize-pane -D 20
bind -r K resize-pane -U 20
bind -r L resize-pane -R 20

# Pane resizing, <Prefix> then alt + vi-directional keys
bind-key M-j resize-pane -D 5
bind-key M-k resize-pane -U 5
bind-key M-h resize-pane -L 5
bind-key M-l resize-pane -R 5

# 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 j command-prompt -p "send pane to:"  "join-pane -t '%%'"


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

### 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'"

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 ###

# 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-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]"

## Centre
set -g window-status-current-format "#[bg=default,fg=#50fa7b]#[fg=black,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]"

## 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


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

### list of plugins ###

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"


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

### Plugins settings ###

# Plugin to save and restore tmux sessions after restart
# * Save with: prefix + Ctrl-s
# * Restore with: prefix + Ctlr-r
  # 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"
# Change default save and restore keybindings
  set -g @resurrect-save "W"
  set -g @resurrect-restore "E"
#set -g @continuum-boot "on"
## Restore Panes
  set -g @resurrect-capture-pane-contents "on"
# This 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 -b "~/.tmux/plugins/tpm/tpm"
run -b "~/.config/tmux/plugins/tpm/tpm"


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