-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwezterm.lua
More file actions
565 lines (498 loc) · 17.1 KB
/
Copy pathwezterm.lua
File metadata and controls
565 lines (498 loc) · 17.1 KB
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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
-- WezTerm Configuration (theme-free base)
--
-- To apply a theme, copy colors.lua from a theme directory to ~/.config/wezterm/
-- Then add near the top:
-- local colors = require("colors")
-- config.color_scheme = colors.scheme
local wezterm = require("wezterm")
local act = wezterm.action
local mux = wezterm.mux
local config = wezterm.config_builder()
-- Try to load theme colors (optional)
local colors_ok, colors = pcall(require, "colors")
if not colors_ok then
colors = nil
end
config.color_scheme = colors.scheme
-- Default accent palette (used if no theme loaded)
local default_accents = {
peach = "#f5a97f",
green = "#a6da95",
blue = "#8aadf4",
mauve = "#c6a0f6",
pink = "#f5bde6",
teal = "#8bd5ca",
yellow = "#eed49f",
red = "#ed8796",
}
-- Get accent color by tab index (picks from dict keys pseudo-randomly)
local function get_accent_for_tab(tab_index)
local accents = (colors and colors.accents) or default_accents
-- Collect keys into array
local keys = {}
for k, _ in pairs(accents) do
table.insert(keys, k)
end
-- Use tab_index to pick a key (consistent per tab, but unordered)
local idx = (tab_index % #keys) + 1
return accents[keys[idx]]
end
-- Helper function to adjust brightness of a hex color
local function adjust_brightness(color, amount)
local r, g, b = color:match("#(%x%x)(%x%x)(%x%x)")
r, g, b = tonumber(r, 16), tonumber(g, 16), tonumber(b, 16)
local function clamp(val)
return math.min(255, math.max(0, val))
end
return string.format("#%02x%02x%02x", clamp(r + amount), clamp(g + amount), clamp(b + amount))
end
-- ============================================================================
-- APPEARANCE
-- ============================================================================
-- Window settings
config.initial_cols = 150
config.initial_rows = 50
config.window_padding = {
left = 10,
right = 10,
top = 10,
bottom = 10,
}
config.window_decorations = "TITLE | RESIZE"
config.window_background_opacity = 0.85
config.macos_window_background_blur = 20
-- Font settings
config.font = wezterm.font_with_fallback({
{ family = "JetBrainsMono Nerd Font Mono", weight = "Regular" },
{ family = "FiraCode Nerd Font", weight = "Regular" },
"Symbols Nerd Font",
})
config.font_size = 14.0
config.font_rules = {
{
intensity = "Bold",
font = wezterm.font({ family = "JetBrainsMono Nerd Font Mono", weight = "Bold" }),
},
{
italic = true,
font = wezterm.font({ family = "JetBrainsMono Nerd Font Mono", style = "Italic" }),
},
}
-- Terminal type
config.term = "xterm-256color"
-- Helper function to get the folder name
local function get_current_working_dir(tab)
local current_dir = tab.active_pane.current_working_dir or ""
if current_dir.file_path then
current_dir = current_dir.file_path
end
local function url_decode(str)
return str:gsub("%%(%x%x)", function(h)
return string.char(tonumber(h, 16))
end)
end
current_dir = url_decode(current_dir)
return string.match(current_dir, "[^/\\]+$") or current_dir
end
-- ============================================================================
-- TAB BAR / STATUS BAR
-- ============================================================================
config.use_fancy_tab_bar = false
config.tab_bar_at_bottom = true
config.hide_tab_bar_if_only_one_tab = false
config.tab_max_width = 32
config.show_new_tab_button_in_tab_bar = true
config.window_frame = {
font_size = 14.0,
}
-- Default status bar colors (used if no theme loaded)
local default_status_colors = {
left_bg = "#a6da95",
left_fg = "#1e2030",
battery_bg = "#a6da95",
battery_fg = "#1e2030",
date_bg = "#8aadf4",
date_fg = "#1e2030",
}
-- Get status bar colors from theme or defaults
local function get_status_colors()
if colors and colors.status_colors then
return colors.status_colors()
end
return default_status_colors
end
-- Status bar with system info (battery, time)
wezterm.on("update-status", function(window, pane)
local date = wezterm.strftime("%H:%M:%S")
local sc = get_status_colors()
-- Get battery info (if available)
local battery = ""
for _, b in ipairs(wezterm.battery_info()) do
local charge = b.state_of_charge * 100
local icon = "♥"
if charge > 80 then
icon = ""
elseif charge > 60 then
icon = ""
elseif charge > 40 then
icon = ""
elseif charge > 20 then
icon = ""
else
icon = ""
end
battery = string.format("%s %.0f%%", icon, charge)
end
-- Left status: workspace name
local workspace = window:active_workspace()
window:set_left_status(wezterm.format({
{ Background = { Color = sc.left_bg } },
{ Foreground = { Color = sc.left_fg } },
{ Text = " " .. workspace .. " " },
}))
-- Right status: battery + date (both with colored backgrounds)
window:set_right_status(wezterm.format({
{ Background = { Color = sc.battery_bg } },
{ Foreground = { Color = sc.battery_fg } },
{ Text = " " .. battery .. " " },
{ Background = { Color = sc.date_bg } },
{ Foreground = { Color = sc.date_fg } },
{ Text = " " .. date .. " " },
}))
end)
-- Tools that should show as tool[dir_name] in tab title
local tool_processes = {
-- Editors
["nvim"] = "nvim",
["vim"] = "vim",
["vi"] = "vi",
-- AI/CLI tools
["claude"] = "claude",
-- JavaScript/Node
["node"] = "node",
["npm"] = "npm",
["yarn"] = "yarn",
["pnpm"] = "pnpm",
["bun"] = "bun",
["deno"] = "deno",
-- Python
["python"] = "py",
["python3"] = "py",
["ipython"] = "ipython",
-- Docker
["docker"] = "docker",
["docker-compose"] = "compose",
["lazydocker"] = "lazydocker",
-- Git
["git"] = "git",
["lazygit"] = "lazygit",
-- Databases
["psql"] = "psql",
["mysql"] = "mysql",
["redis-cli"] = "redis",
["mongosh"] = "mongo",
["sqlite3"] = "sqlite",
-- Kubernetes
["kubectl"] = "kubectl",
["k9s"] = "k9s",
["helm"] = "helm",
-- Infrastructure
["terraform"] = "tf",
["ansible"] = "ansible",
-- System monitoring
["htop"] = "htop",
["btop"] = "btop",
["top"] = "top",
-- Other languages
["go"] = "go",
["cargo"] = "cargo",
["ruby"] = "ruby",
["irb"] = "irb",
-- Remote
["ssh"] = "ssh",
}
-- Get smart tab title based on foreground process
local function get_smart_title(tab)
local dir_name = get_current_working_dir(tab)
local process_name = tab.active_pane.foreground_process_name or ""
-- Extract just the binary name (remove path)
process_name = string.match(process_name, "[^/\\]+$") or process_name
local tool_label = tool_processes[process_name]
if tool_label then
return tool_label .. "[" .. dir_name .. "]"
end
return dir_name
end
-- Tab title format with accent colors
wezterm.on("format-tab-title", function(tab, tabs, panes, cfg, hover, max_width)
local title = tab.tab_title
if not title or #title == 0 then
title = get_smart_title(tab)
end
if not title or #title == 0 then
title = tab.active_pane.title
end
-- Truncate if needed
if #title > max_width - 3 then
title = string.sub(title, 1, max_width) .. "…"
end
local accent = get_accent_for_tab(tab.tab_index)
local tab_text = string.format(" %d: %s ", tab.tab_index + 1, title)
-- Get background color from palette or use defaults
local bg = "#1e2030"
local fg = "#cad3f5"
if colors and colors.palette then
bg = colors.palette.mantle or colors.palette.bg_dark or bg
fg = colors.palette.text or colors.palette.fg or fg
end
if tab.is_active then
return {
{ Background = { Color = accent } },
{ Foreground = { Color = bg } },
{ Attribute = { Intensity = "Bold" } },
{ Text = tab_text },
}
else
-- Use dimmed colors for inactive tabs (dimmed version of active tab colors)
local dimmed_accent = adjust_brightness(accent, -70)
local dimmed_fg = adjust_brightness(bg, -70)
return {
{ Background = { Color = dimmed_accent } },
{ Foreground = { Color = dimmed_fg } },
{ Attribute = { Intensity = "Normal" } },
{ Text = tab_text },
}
end
end)
-- ============================================================================
-- MULTIPLEXING SETTINGS
-- ============================================================================
config.unix_domains = {
{
name = "unix",
},
}
-- Mouse support
config.mouse_bindings = {
{
event = { Down = { streak = 1, button = "Right" } },
mods = "NONE",
action = act.PasteFrom("Clipboard"),
},
}
-- ============================================================================
-- PANE VISIBILITY
-- ============================================================================
config.underline_thickness = "2px"
config.colors = {
split = "#f5f5f5",
}
config.inactive_pane_hsb = {
saturation = 0.8,
brightness = 0.7,
}
-- ============================================================================
-- KEYBINDINGS (tmux-style with CTRL+B as leader)
-- ============================================================================
config.leader = { key = "b", mods = "CTRL", timeout_milliseconds = 2000 }
config.keys = {
-- ========== PANE SPLITTING ==========
{
key = "|",
mods = "LEADER|SHIFT",
action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }),
},
{
key = "-",
mods = "LEADER",
action = act.SplitVertical({ domain = "CurrentPaneDomain" }),
},
-- ========== PANE NAVIGATION ==========
{ key = "h", mods = "LEADER", action = act.ActivatePaneDirection("Left") },
{ key = "j", mods = "LEADER", action = act.ActivatePaneDirection("Down") },
{ key = "k", mods = "LEADER", action = act.ActivatePaneDirection("Up") },
{ key = "l", mods = "LEADER", action = act.ActivatePaneDirection("Right") },
{ key = "LeftArrow", mods = "LEADER", action = act.ActivatePaneDirection("Left") },
{ key = "RightArrow", mods = "LEADER", action = act.ActivatePaneDirection("Right") },
{ key = "UpArrow", mods = "LEADER", action = act.ActivatePaneDirection("Up") },
{ key = "DownArrow", mods = "LEADER", action = act.ActivatePaneDirection("Down") },
-- ========== PANE RESIZING ==========
{ key = "H", mods = "LEADER|SHIFT", action = act.AdjustPaneSize({ "Left", 5 }) },
{ key = "J", mods = "LEADER|SHIFT", action = act.AdjustPaneSize({ "Down", 5 }) },
{ key = "K", mods = "LEADER|SHIFT", action = act.AdjustPaneSize({ "Up", 5 }) },
{ key = "L", mods = "LEADER|SHIFT", action = act.AdjustPaneSize({ "Right", 5 }) },
-- ========== TAB/WINDOW MANAGEMENT ==========
{ key = "c", mods = "LEADER", action = act.SpawnTab("CurrentPaneDomain") },
{ key = "n", mods = "LEADER", action = act.ActivateTabRelative(1) },
{ key = "p", mods = "LEADER", action = act.ActivateTabRelative(-1) },
{ key = "[", mods = "ALT", action = act.ActivateTabRelative(-1) },
{ key = "]", mods = "ALT", action = act.ActivateTabRelative(1) },
{ key = "l", mods = "ALT", action = act.ActivatePaneDirection("Next") },
{ key = "x", mods = "LEADER", action = act.CloseCurrentPane({ confirm = true }) },
{ key = "&", mods = "LEADER|SHIFT", action = act.CloseCurrentTab({ confirm = true }) },
{ key = "w", mods = "ALT", action = act.ShowTabNavigator },
-- Direct tab switching (1-9)
{ key = "1", mods = "LEADER", action = act.ActivateTab(0) },
{ key = "2", mods = "LEADER", action = act.ActivateTab(1) },
{ key = "3", mods = "LEADER", action = act.ActivateTab(2) },
{ key = "4", mods = "LEADER", action = act.ActivateTab(3) },
{ key = "5", mods = "LEADER", action = act.ActivateTab(4) },
{ key = "6", mods = "LEADER", action = act.ActivateTab(5) },
{ key = "7", mods = "LEADER", action = act.ActivateTab(6) },
{ key = "8", mods = "LEADER", action = act.ActivateTab(7) },
{ key = "9", mods = "LEADER", action = act.ActivateTab(8) },
{ key = "1", mods = "ALT", action = act.ActivateTab(0) },
{ key = "2", mods = "ALT", action = act.ActivateTab(1) },
{ key = "3", mods = "ALT", action = act.ActivateTab(2) },
{ key = "4", mods = "ALT", action = act.ActivateTab(3) },
{ key = "5", mods = "ALT", action = act.ActivateTab(4) },
{ key = "6", mods = "ALT", action = act.ActivateTab(5) },
{ key = "7", mods = "ALT", action = act.ActivateTab(6) },
{ key = "8", mods = "ALT", action = act.ActivateTab(7) },
{ key = "9", mods = "ALT", action = act.ActivateTab(8) },
-- Move tab to the left (relative)
{ key = "{", mods = "LEADER", action = act.MoveTabRelative(-1) },
-- Move tab to the right (relative)
{ key = "}", mods = "LEADER", action = act.MoveTabRelative(1) },
-- ========== ZOOM/FULLSCREEN PANE ==========
{ key = "z", mods = "LEADER", action = act.TogglePaneZoomState },
-- ========== RENAME TAB ==========
{
key = ",",
mods = "LEADER",
action = act.PromptInputLine({
description = "Enter new tab name:",
action = wezterm.action_callback(function(window, pane, line)
if line then
window:active_tab():set_title(line)
end
end),
}),
},
-- ========== COPY MODE ==========
{ key = "[", mods = "LEADER", action = act.ActivateCopyMode },
-- ========== COMMAND PALETTE ==========
{ key = ":", mods = "LEADER|SHIFT", action = act.ActivateCommandPalette },
-- ========== CONFIG RELOAD ==========
{ key = "r", mods = "LEADER", action = act.ReloadConfiguration },
-- ========== WORKSPACE SWITCHING ==========
{ key = "s", mods = "LEADER", action = act.ShowLauncherArgs({ flags = "FUZZY|WORKSPACES" }) },
-- ========== LAYOUT PRESETS ==========
-- tlay-focus: Two stacked left, full horizontal right
{
key = "F1",
mods = "LEADER",
action = wezterm.action_callback(function(window, pane)
pane:split({ direction = "Right", size = 0.35 })
window:perform_action(act.ActivatePaneDirection("Left"), pane)
local left_pane = window:active_pane()
left_pane:split({ direction = "Bottom", size = 0.30 })
window:perform_action(act.ActivatePaneDirection("Up"), window:active_pane())
end),
},
-- tlay-wide: Top wide, two bottom panes
{
key = "F2",
mods = "LEADER",
action = wezterm.action_callback(function(window, pane)
pane:split({ direction = "Bottom", size = 0.4 })
local bottom_pane = window:active_pane()
bottom_pane:split({ direction = "Right", size = 0.5 })
window:perform_action(act.ActivatePaneDirection("Up"), window:active_pane())
end),
},
-- tlay-3-col: Three equal vertical columns
{
key = "F3",
mods = "LEADER",
action = wezterm.action_callback(function(window, pane)
-- Split 1/3 off the right (pane is now 66% wide)
local left_two = pane:split({ direction = "Right", size = 0.66 })
-- Split the remaining 66% in half to get 33% | 33% | 33%
left_two:split({ direction = "Right", size = 0.5 })
end),
},
-- tlay-grid: 2x2 equal grid
{
key = "F4",
mods = "LEADER",
action = wezterm.action_callback(function(window, pane)
pane:split({ direction = "Right", size = 0.5 })
local right_pane = window:active_pane()
right_pane:split({ direction = "Bottom", size = 0.5 })
window:perform_action(act.ActivatePaneDirection("Left"), window:active_pane())
local left_pane = window:active_pane()
left_pane:split({ direction = "Bottom", size = 0.5 })
window:perform_action(act.ActivatePaneDirection("Up"), window:active_pane())
end),
},
-- tlay-v55: Simple vertical split 55/45
{
key = "F5",
mods = "LEADER",
action = wezterm.action_callback(function(window, pane)
pane:split({ direction = "Right", size = 0.45 })
window:perform_action(act.ActivatePaneDirection("Left"), window:active_pane())
end),
},
-- tlay-reset: Close all panes except current, close other tabs
{
key = "F8",
mods = "LEADER",
action = wezterm.action_callback(function(window, pane)
local tab = window:active_tab()
local mux_window = window:mux_window()
for _, p in ipairs(tab:panes()) do
if p:pane_id() ~= pane:pane_id() then
p:activate()
window:perform_action(act.CloseCurrentPane({ confirm = false }), p)
end
end
local tabs = mux_window:tabs()
local current_tab_id = tab:tab_id()
for _, t in ipairs(tabs) do
if t:tab_id() ~= current_tab_id then
t:activate()
window:perform_action(act.CloseCurrentTab({ confirm = false }), window:active_pane())
end
end
tab:set_title("")
end),
},
}
-- ============================================================================
-- KEY TABLES
-- ============================================================================
config.key_tables = {
resize_pane = {
{ key = "h", action = act.AdjustPaneSize({ "Left", 1 }) },
{ key = "j", action = act.AdjustPaneSize({ "Down", 1 }) },
{ key = "k", action = act.AdjustPaneSize({ "Up", 1 }) },
{ key = "l", action = act.AdjustPaneSize({ "Right", 1 }) },
{ key = "Escape", action = "PopKeyTable" },
{ key = "Enter", action = "PopKeyTable" },
},
}
-- ============================================================================
-- SHELL CONFIGURATION
-- ============================================================================
config.default_prog = { "/bin/zsh", "-l" }
-- ============================================================================
-- PERFORMANCE / MISC
-- ============================================================================
config.scrollback_lines = 10000
config.enable_scroll_bar = false
config.adjust_window_size_when_changing_font_size = false
config.use_ime = true
config.window_close_confirmation = "NeverPrompt"
-- ============================================================================
-- STARTUP BEHAVIOR
-- ============================================================================
wezterm.on("gui-startup", function(cmd)
local args = cmd and cmd.args or {}
local tab, pane, window = mux.spawn_window({
workspace = "main",
args = args,
})
end)
return config