-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_wezterm.lua
More file actions
157 lines (137 loc) · 4.96 KB
/
dot_wezterm.lua
File metadata and controls
157 lines (137 loc) · 4.96 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
local wezterm = require("wezterm")
local config = wezterm.config_builder()
local HOME = os.getenv("HOME")
local mode_file = HOME .. "/.bg_mode"
-- === THEMING WORKFLOW ===
--
-- STARTUP:
-- 1. get_current_scheme() reads system appearance → writes ~/.bg_mode → reads ~/.theme_* → maps to WezTerm scheme
-- 2. File watchers set up for ~/.theme_light and ~/.theme_dark
-- 3. Event handler registered for config reloads
--
-- SYSTEM THEME CHANGE:
-- 1. System appearance changes → triggers "window-config-reloaded" event
-- 2. get_current_scheme() detects new appearance → updates ~/.bg_mode → reads different theme file
-- 3. New scheme applied via window:set_config_overrides()
--
-- THEME FILE CHANGE:
-- 1. External tool modifies ~/.theme_* → file watcher triggers reload event
-- 2. get_current_scheme() reads updated file content (same ~/.bg_mode)
-- 3. New scheme applied immediately
--
-- FILES: ~/.bg_mode (tracks light/dark), ~/.theme_light, ~/.theme_dark (contain theme names)
-- Theme mapping — auto-generated by theme-generate, do not edit manually
-- Source: ~/.config/themes/registry/*.yaml → ~/.wezterm_themes.lua
local themes = dofile(HOME .. "/.wezterm_themes.lua").themes
-- Helper functions
local function read_file(path)
local file = io.open(path, "r")
if file then
local content = file:read("*line")
file:close()
return content and content:match("%S") and content:gsub("%s+", "")
end
end
local function write_file(path, content)
local file = io.open(path, "w")
if file then
file:write(content)
file:close()
end
end
local function get_theme_scheme(theme_name, bg_mode)
local theme = themes[theme_name]
if type(theme) == "table" then
local resolved = theme[bg_mode] or theme.dark
wezterm.log_warn("Using theme: " .. resolved .. " for mode: " .. bg_mode)
return resolved
end
if theme and theme ~= "null" then
return theme
end
-- If theme doesn't exist or has no WezTerm built-in, use a safe default
wezterm.log_warn("Unknown or unmapped WezTerm scheme: " .. tostring(theme_name) .. ", falling back to default")
return bg_mode == "dark" and "nordfox" or "dawnfox"
end
local function get_current_scheme()
local is_dark = wezterm.gui and wezterm.gui.get_appearance():find("Dark")
local bg_mode = is_dark and "dark" or "light"
write_file(mode_file, bg_mode)
local theme = read_file(HOME .. "/.theme_" .. bg_mode)
if theme then
return get_theme_scheme(theme, bg_mode)
end
return bg_mode == "dark" and "nordfox" or "dawnfox"
end
-- === THEMING & CONFIG RELOAD ===
-- Flow: System appearance change OR theme file change → reload event → update color scheme
-- Watch theme files for changes
wezterm.add_to_config_reload_watch_list(HOME .. "/.theme_light")
wezterm.add_to_config_reload_watch_list(HOME .. "/.theme_dark")
-- Handle config reloads: update color scheme when watched files change
wezterm.on("window-config-reloaded", function(window)
local overrides = window:get_config_overrides() or {}
overrides.color_scheme = get_current_scheme()
window:set_config_overrides(overrides)
end)
-- Core configuration
config.initial_cols = 180
config.initial_rows = 60
config.enable_kitty_keyboard = false
config.color_scheme = get_current_scheme()
config.font = wezterm.font("JetBrainsMonoNL Nerd Font")
config.font_size = 14
-- UI settings
config.enable_tab_bar = true
config.use_fancy_tab_bar = true
config.hide_tab_bar_if_only_one_tab = true
config.window_decorations = "RESIZE"
config.window_background_opacity = 1
config.macos_window_background_blur = 5
config.window_padding = { left = 1, right = 0, top = 2, bottom = 0 }
-- Key bindings
local disable_keys = {
{ key = "UpArrow", mods = "SHIFT|CTRL" },
{ key = "DownArrow", mods = "SHIFT|CTRL" },
{ key = "LeftArrow", mods = "SHIFT|CTRL" },
{ key = "RightArrow", mods = "SHIFT|CTRL" },
{ key = "RightArrow", mods = "CTRL" },
{ key = "LeftArrow", mods = "CTRL" },
{ key = "Enter", mods = "ALT" },
{ key = "Enter", mods = "CTRL" },
}
config.keys = {}
for _, key in ipairs(disable_keys) do
table.insert(config.keys, { key = key.key, mods = key.mods, action = wezterm.action.DisableDefaultAssignment })
end
-- Custom key bindings
local custom_keys = {
{ key = "Enter", mods = "SHIFT|CTRL", action = wezterm.action.ToggleFullScreen },
{ key = "Enter", mods = "SHIFT", action = wezterm.action({ SendString = "\x1b[13;2u" }) },
{ key = "C", mods = "SHIFT|CTRL", action = wezterm.action.ActivateCopyMode },
{
key = "E",
mods = "CTRL|SHIFT",
action = wezterm.action.PromptInputLine({
description = "Enter new name for tab",
action = wezterm.action_callback(function(window, pane, line)
if line then
window:active_tab():set_title(line)
end
end),
}),
},
{
key = "T",
mods = "CTRL|SHIFT",
action = wezterm.action_callback(function(window, pane)
local overrides = window:get_config_overrides() or {}
overrides.color_scheme = get_current_scheme()
window:set_config_overrides(overrides)
end),
},
}
for _, key in ipairs(custom_keys) do
table.insert(config.keys, key)
end
return config