-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_tmux_conf.sh
executable file
·483 lines (433 loc) · 11.5 KB
/
generate_tmux_conf.sh
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
#!/usr/bin/env bash
#
# Copyright (c) 2024-2025: [email protected]
# License: MIT
#
# Part of https://github.com/jaclu/tmux-keybtest
#
#
# This will generate a tmux.conf adjusted to the used tmux version
#
writeln() {
printf "%s\n" "$1" >>"$tmux_conf"
}
header_1() {
writeln
writeln "# -- $1"
}
header_2() {
writeln
writeln "#"
writeln "# $1"
writeln "#"
}
header_3() {
writeln
writeln
writeln "#==========================================================="
writeln "#"
writeln "# Segment covering modifier: $1"
writeln "#"
writeln "#==========================================================="
}
bind_char() {
local output="bind -n "
[[ -z "$1" ]] && {
echo "ERROR: call to bind_char() with no param"
exit 1
}
case "$2" in
s | S) output+="'${mod}$1' display-message '${mod}$1'" ;;
d | D) output+="\"${mod}$1\" display-message \"${mod}$1\"" ;;
*) output+="${mod}$1 display-message \"${mod}$1\"" ;;
esac
writeln "$output"
}
base_conf() {
writeln "#==========================================================="
writeln "#"
writeln "# Tmux conf for teting keyboard implementation, and what"
writeln "# non standard sequences it can generate. - Arrows with modifiers etc"
writeln "#"
writeln "#==========================================================="
writeln ""
writeln "# Created for tmux version: $tmux_vers"
writeln ""
writeln "#"
writeln "# Minimal config"
writeln "#"
writeln "set-option -g prefix C-x"
writeln "bind C-c kill-server"
writeln "set-option -g mouse on"
writeln "set-option -s escape-time 100"
writeln "set-option -g display-time 1000"
writeln "set-option -g visual-bell on"
writeln "set -g focus-events on"
tmux_vers_ok 3.2 && writeln "set -g extended-keys on"
# tmux_vers_ok 2.8 && writeln 'bind Any display "Not defined"'
tmux_vers_ok 2.9 && {
writeln
writeln "#"
writeln "# Display some hints in status bar left row 2 & 3"
writeln "#"
writeln "set-option -g status 3"
writeln "set-option -g status-format[1] 'Displays keys and mouse events recognized by tmux in status-bar'"
writeln "set-option -g status-format[2] 'To exit press C-x then C-c. To test C-x press it twice'"
}
writeln
writeln "#"
writeln "# Display prefix key pressed in Status bar right"
writeln "#"
writeln "set-option -g status-right-length 0"
writeln "set-option -g status-right '#{?client_prefix,Prefix #[fg=colour231]#[bg=colour04]C-x#[default] - Press C-c to exit,}'"
writeln "run-shell -b 'sleep 0.5 ; tmux send-keys \"showkey -a\" C-M'"
}
mouse_event_via_script() {
# Doesn't work right now, using mouse_events() instead
header_2 "Mouse"
writeln "bind -n '${mod}WheelUpPane' run-shell -b '\$f_mouse_event ${mod}WheelUpPane'"
writeln "bind -n '${mod}WheelDownPane' run-shell -b '\$f_mouse_event ${mod}WheelDownPane'"
writeln "bind -n '${mod}MouseDown1Pane' run-shell -b '\$f_mouse_event ${mod}MouseDown1Pane'"
writeln "bind -n '${mod}MouseUp1Pane' run-shell -b '\$f_mouse_event ${mod}MouseUp1Pane'"
writeln "bind -n '${mod}MouseDrag1Pane' run-shell -b '\$f_mouse_event ${mod}MouseDrag1Pane'"
writeln "bind -n '${mod}MouseDragEnd1Pane' run-shell -b '\$f_mouse_event ${mod}MouseDragEnd1Pane'"
writeln "bind -n '${mod}MouseDown2Pane' run-shell -b '\$f_mouse_event ${mod}MouseDown2Pane'"
writeln "bind -n '${mod}MouseUp2Pane' run-shell -b '\$f_mouse_event ${mod}MouseUp2Pane'"
writeln "bind -n '${mod}MouseDrag2Pane' run-shell -b '\$f_mouse_event ${mod}MouseDrag2Pane'"
writeln "bind -n '${mod}MouseDragEnd2Pane' run-shell -b '\$f_mouse_event ${mod}MouseDragEnd2Pane'"
writeln "bind -n '${mod}MouseDown3Pane' run-shell -b '\$f_mouse_event ${mod}MouseDown3Pane'"
writeln "bind -n '${mod}MouseUp3Pane' run-shell -b '\$f_mouse_event ${mod}MouseUp3Pane'"
writeln "bind -n '${mod}MouseDrag3Pane' run-shell -b '\$f_mouse_event ${mod}MouseDrag3Pane'"
writeln "bind -n '${mod}MouseDragEnd3Pane' run-shell -b '\$f_mouse_event ${mod}MouseDragEnd3Pane'"
writeln "bind -n '${mod}SecondClick1Pane' run-shell -b '\$f_mouse_event ${mod}SecondClick1Pane'"
writeln "bind -n '${mod}SecondClick2Pane' run-shell -b '\$f_mouse_event ${mod}SecondClick2Pane'"
writeln "bind -n '${mod}SecondClick3Pane' run-shell -b '\$f_mouse_event ${mod}SecondClick3Pane'"
writeln "bind -n '${mod}DoubleClick1Pane' run-shell -b '\$f_mouse_event ${mod}DoubleClick1Pane'"
writeln "bind -n '${mod}DoubleClick2Pane' run-shell -b '\$f_mouse_event ${mod}DoubleClick2Pane'"
writeln "bind -n '${mod}DoubleClick3Pane' run-shell -b '\$f_mouse_event ${mod}DoubleClick3Pane'"
writeln "bind -n '${mod}TripleClick1Pane' run-shell -b '\$f_mouse_event ${mod}TripleClick1Pane'"
writeln "bind -n '${mod}TripleClick2Pane' run-shell -b '\$f_mouse_event ${mod}TripleClick2Pane'"
writeln "bind -n '${mod}TripleClick3Pane' run-shell -b '\$f_mouse_event ${mod}TripleClick3Pane'"
}
mouse_events() {
header_2 "Mouse"
bind_char WheelUpPane d
bind_char WheelDownPane d
bind_char MouseDown1Pane d
bind_char MouseUp1Pane d
bind_char MouseDrag1Pane d
bind_char MouseDragEnd1Pane d
bind_char MouseDown2Pane d
bind_char MouseUp2Pane d
bind_char MouseDrag2Pane d
bind_char MouseDragEnd2Pane d
bind_char MouseDown3Pane d
bind_char MouseUp3Pane d
bind_char MouseDrag3Pane d
bind_char MouseDragEnd3Pane d
bind_char DoubleClick1Pane d
bind_char DoubleClick2Pane d
bind_char DoubleClick3Pane d
bind_char TripleClick1Pane d
bind_char TripleClick2Pane d
bind_char TripleClick3Pane d
tmux_vers_ok 3.2 || return
bind_char SecondClick1Pane d
bind_char SecondClick2Pane d
bind_char SecondClick3Pane d
}
lower_case_chars() {
case "$mod" in
S- | C-S- | M-S- | C-M-S-) tmux_vers_ok 3.5 || return ;;
*) ;;
esac
header_1 "Lower Case"
bind_char a
bind_char b
bind_char c
bind_char d
bind_char e
bind_char f
bind_char g
bind_char h
# Messes with Escaoe & Enter on older versions
case "$mod" in
C- | C-M-)
tmux_vers_ok 3.5 && {
bind_char i
bind_char m
}
;;
*) ;;
esac
bind_char j
bind_char k
bind_char l d
bind_char n
bind_char o
bind_char p d
bind_char q
bind_char r
bind_char s d
bind_char t
bind_char u
bind_char v d
bind_char w
case "$mod" in
C-)
# Special case bind this to the root table, in order to display prefix
# on second press
writeln "bind '${mod}x' display-message '${mod}x'"
;;
*) bind_char x ;;
esac
bind_char y
bind_char z
bind_char "å"
bind_char "ä"
bind_char "ö"
header_1 "acute accent"
bind_char "á"
bind_char "é"
bind_char "í"
bind_char "ó"
bind_char "ú"
bind_char "ý"
}
upper_case_chars() {
case "$mod" in
# C-) return ;;
*) ;;
esac
header_1 "Upper Case"
bind_char A
bind_char B
bind_char C
bind_char D
bind_char E
bind_char F
bind_char G
bind_char H
# Messes with Escaoe & Enter on older versions
case "$mod" in
C- | C-M-)
tmux_vers_ok 3.5 && {
bind_char I
bind_char M
}
;;
*) ;;
esac
bind_char J
bind_char K
bind_char L
bind_char N
bind_char O
bind_char P d
bind_char Q
bind_char R
bind_char S d
bind_char T
bind_char U
bind_char V d
bind_char W
bind_char X d
bind_char Y
bind_char Z
bind_char "Å"
bind_char "Ä"
bind_char "Ö"
header_1 "acute accent"
bind_char "Á"
bind_char "É"
bind_char "Í"
bind_char "Ó"
bind_char "Ú"
bind_char "Ý"
}
non_letter_regular_cars() {
header_1 "non-letter regular keys"
bind_char "§"
bind_char "1"
bind_char "2"
bind_char "3"
bind_char "4"
bind_char "5"
bind_char "6"
bind_char "7"
bind_char "8"
bind_char "9"
bind_char "0"
bind_char "±" # plus-minus sign
bind_char "°" # degree symbol
bind_char "!"
bind_char "@"
bind_char "#" s
bind_char "£"
bind_char "€"
bind_char "^"
bind_char "("
bind_char ")"
bind_char "-"
bind_char "_"
bind_char "="
bind_char "´"
bind_char "+"
case "$mod" in
C- | C-M-) tmux_vers_ok 3.5 && bind_char "[" ;;
*) ;;
esac
bind_char "]"
bind_char "\\\\"
bind_char ":"
bind_char "'" d
bind_char ","
bind_char "."
bind_char "<" d
bind_char ">" d
bind_char "?" d
tmux_vers_ok 3.0 && bind_char ";" d
tmux_vers_ok 3.3 || {
case "$mod" in
C- | C-M-) return ;;
*) ;;
esac
}
bind_char "\`" d
bind_char "/"
tmux_vers_ok 3.5 || {
case "$mod" in
C- | C-M-) return ;;
*) ;;
esac
}
bind_char '~' s
bind_char '$' s
bind_char % d
bind_char "\&" d
bind_char '*' d
bind_char "{" d
bind_char "}" d
bind_char "|" d
bind_char '"' s
}
special_basic_keys() {
header_2 "Special basic keys"
bind_char Tab
bind_char bTab
bind_char Enter
bind_char Space
bind_char BSpace
bind_char Up
bind_char Down
bind_char Left
bind_char Right
tmux_vers_ok 3.3 || {
case "$mod" in
C- | C-S- | C-M- | C-M-S-) return ;;
*) ;;
esac
}
bind_char Escape
}
func_keys() {
header_2 "Function keys"
bind_char F1
bind_char F2
bind_char F3
bind_char F4
bind_char F5
bind_char F6
bind_char F7
bind_char F8
bind_char F9
bind_char F10
bind_char F11
bind_char F12
}
above_arrows() {
header_2 "Group normally above arrows"
bind_char IC # Insert
bind_char DC # Delete
bind_char Home
bind_char End
bind_char PgUp
bind_char PgDn
}
num_keyboard() {
header_2 "Num Keyboard"
bind_char KP/
bind_char "KP*" d
bind_char KP-
bind_char KP7
bind_char KP8
bind_char KP9
bind_char KP+
bind_char KP4
bind_char KP5
bind_char KP6
bind_char KP1
bind_char KP2
bind_char KP3
bind_char KPEnter
bind_char KP0
bind_char KP.
}
regular_chars() {
case "$mod" in
S- | C-S- | M-S- | C-M-S-) return ;;
*) ;;
esac
header_2 "Regular keys"
lower_case_chars
upper_case_chars
non_letter_regular_cars
}
do_keys() {
# mouse_event_via_script
mouse_events
regular_chars
special_basic_keys
func_keys
above_arrows
num_keyboard
}
process_mod() {
mod="$1"
case "$mod" in
"") mod_long="No Prefix" ;;
S-) mod_long="Shift" ;;
C-) mod_long="Control" ;;
M-) mod_long="Meta" ;;
C-S-) mod_long="Control-Shift" ;;
M-S-) mod_long="Meta-Shift" ;;
C-M-) mod_long="Control-Meta" ;;
C-M-S-) mod_long="Control-Meta-Shift" ;;
*) mod_long="Unknown mod: $mod" ;;
esac
header_3 "$mod_long"
do_keys
}
#===============================================================
#
# Main
#
#===============================================================
d_tkbtst_location="$(dirname "$(realpath "$0")")"
. "$d_tkbtst_location"/utils.sh
tmux_vers_ok 2.4 || {
echo
echo "ERROR: This requires tmux >= 2.4!"
echo
exit 1
}
rm -f "$tmux_conf"
base_conf
process_mod ""
process_mod "S-"
process_mod "C-"
process_mod "C-S-"
process_mod "M-"
process_mod "M-S-"
process_mod "C-M-"
process_mod "C-M-S-"