-
Notifications
You must be signed in to change notification settings - Fork 1
/
wezterm.lua
290 lines (261 loc) · 8.73 KB
/
wezterm.lua
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
local wezterm = require("wezterm")
local act = wezterm.action
local config = {}
if wezterm.config_builder then config = wezterm.config_builder() end
config.automatically_reload_config = true
-- startup
config.default_prog = { "/bin/zsh", "-l" }
config.audible_bell = "Disabled" -- NO BELLS
config.window_close_confirmation = "NeverPrompt" -- Shutdown w/o requiring confirmation
-- colors
function get_appearance()
local appearance = "Dark"
if wezterm.gui then appearance = wezterm.gui.get_appearance() end
return appearance
end
function scheme_for_appearance(appearance)
if appearance:find("Dark") then
return "Catppuccin Mocha"
else
return "Catppuccin Latte"
end
end
config.color_scheme = scheme_for_appearance(get_appearance())
config.set_environment_variables = {
THEME_MODE = get_appearance(),
}
-- look & feel
local font_size = 14.0
config.adjust_window_size_when_changing_font_size = false
config.window_frame = {
font = wezterm.font({ family = "JetBrainsMono Nerd Font Mono" }),
font_size = font_size,
}
config.window_decorations = "RESIZE"
config.font = wezterm.font("JetBrainsMono Nerd Font Mono", { weight = "Medium" })
config.font_size = font_size
config.max_fps = 100
config.window_padding = {
left = 5,
right = 5,
top = 10,
bottom = 0,
}
wezterm.on("window-resized", function(window, pane)
local tab = pane:tab()
if tab == nil then return end
local cols = tab:get_size().cols
local overrides = window:get_config_overrides() or {}
local default_font_size = 14
if cols >= 300 then overrides.font_size = 15 end
if overrides.font_size ~= default_font_size then window:set_config_overrides({ font_size = default_font_size }) end
end)
-- tab bar
config.tab_max_width = 24
config.tab_bar_at_bottom = false
config.use_fancy_tab_bar = false
wezterm.on("format-tab-title", function(tab, tabs, panes, cfg, hover, max_width)
local cwd = tab.active_pane.current_working_dir
local process_text = tab.active_pane.foreground_process_name
local label = ""
if process_text == nil then process_text = "" end
if cwd == nil then cwd = "" end
local dir_name = tostring(cwd):match("([^/]+)$")
local process = tostring(process_text):match("([^/]+)$")
if process == nil or process == "zsh" then
label = dir_name ~= nil and dir_name or "-*-"
else
label = process .. " @ " .. dir_name
end
if #label > max_width - 2 then label = string.sub(label, 1, max_width - 3) .. "…" end
return " " .. label .. " "
end)
-- mappings
config.leader = { key = " ", mods = "CTRL", timeout_milliseconds = 500 } -- keep my tmux muscle memory
config.keys = {
{
key = "r",
mods = "CMD|SHIFT",
action = act.ReloadConfiguration,
},
{
key = "l",
mods = "ALT",
action = act.ShowLauncherArgs({ flags = "FUZZY|LAUNCH_MENU_ITEMS|WORKSPACES|COMMANDS|TABS" }),
},
{
key = "l",
mods = "CMD|SHIFT",
action = act.ShowLauncherArgs({ flags = "FUZZY|LAUNCH_MENU_ITEMS|WORKSPACES|COMMANDS|TABS" }),
},
{
key = "P",
mods = "CMD",
action = wezterm.action.ActivateCommandPalette,
},
{
key = "|",
mods = "LEADER",
action = wezterm.action_callback(function(_, pane)
local dimensions = pane:get_dimensions()
local size = 0.5
if dimensions.cols >= 300 then size = 0.33 end
pane:split({ direction = "Right", size = size })
end),
},
{
key = "_",
mods = "LEADER",
action = act.SplitVertical({ domain = "CurrentPaneDomain" }),
},
{
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 = "r",
mods = "LEADER",
action = act.ActivateKeyTable({
name = "resize_pane",
one_shot = false,
}),
},
{
key = "z",
mods = "LEADER",
action = act.TogglePaneZoomState,
},
{
key = "s",
mods = "LEADER",
action = act.ShowLauncherArgs({ flags = "WORKSPACES|FUZZY" }),
},
{
key = " ",
mods = "LEADER",
action = act.RotatePanes("Clockwise"),
},
{
key = "f",
mods = "LEADER",
action = act.PaneSelect,
},
{
key = "x",
mods = "LEADER",
action = act.PaneSelect({ mode = "SwapWithActive" }),
},
{
key = "t",
mods = "LEADER",
action = wezterm.action_callback(function(window, cur_pane)
local cur_tab = window:active_tab()
local panes = cur_tab:panes_with_info()
local get_newest_tab = function()
local tabs = window:mux_window():tabs_with_info()
local max_idx = 0
local newest_tab = nil
for _, tab in ipairs(tabs) do
if tab.index >= max_idx then
max_idx = tab.index
newest_tab = tab.tab
end
end
return newest_tab
end
local contains = function(tbl, val)
for _, entry in ipairs(tbl) do
if entry == val then return true end
end
return false
end
window:perform_action(act.SpawnTab({ DomainName = "local" }), cur_pane)
local new_tab = get_newest_tab()
new_tab:activate()
local working_new_pane = new_tab:active_pane()
local seen_pane_ids = {}
local last_left_col = 0
local last_top_row = 0
while #seen_pane_ids ~= #panes do
for _, pane in ipairs(panes) do
if contains(seen_pane_ids, pane.pane:pane_id()) then goto continue end
local cwd = pane.pane:get_current_working_dir()
-- "main" pane already exists
if pane.left == 0 and pane.top == 0 then
table.insert(seen_pane_ids, pane.pane:pane_id())
goto continue
end
-- same starting col -> split into top/bottom
if pane.left == last_left_col then
working_new_pane = working_new_pane:split({ cwd = cwd.path, direction = "Bottom" })
last_top_row = pane.top
-- same starting row -> split into left/right
elseif pane.top == last_top_row then
working_new_pane = working_new_pane:split({ cwd = cwd.path, direction = "Right" })
last_left_col = pane.left
end
table.insert(seen_pane_ids, pane.pane:pane_id())
::continue::
end
end
end),
},
{ key = "+", mods = "CMD", action = act.IncreaseFontSize },
{ key = "-", mods = "CMD", action = act.DecreaseFontSize },
{ key = ".", mods = "CMD", action = act.ResetFontSize },
{ key = "u", mods = "LEADER", action = act.QuickSelect },
{
key = ",",
mods = "LEADER",
action = act.PromptInputLine({
description = "New tab name",
action = wezterm.action_callback(function(window, pane, line)
if line then window:active_tab():set_title(line) end
end),
}),
},
{
key = "$",
mods = "LEADER",
action = act.PromptInputLine({
description = "New session name",
action = wezterm.action_callback(function(window, pane, line)
if line then wezterm.mux.rename_workspace(wezterm.mux.get_active_workspace(), line) end
end),
}),
},
}
config.key_tables = {
resize_pane = {
{ key = "LeftArrow", action = act.AdjustPaneSize({ "Left", 1 }) },
{ key = "RightArrow", action = act.AdjustPaneSize({ "Right", 1 }) },
{ key = "UpArrow", action = act.AdjustPaneSize({ "Up", 1 }) },
{ key = "DownArrow", action = act.AdjustPaneSize({ "Down", 1 }) },
-- Cancel the mode by pressing escape
{ key = "Escape", action = "PopKeyTable" },
},
}
-- better hyperlink detection
local link_rules = wezterm.default_hyperlink_rules()
table.insert(link_rules, {
regex = [[\b([A-Z]{2,9}?-\d+?)\b]],
format = "https://jira.kdc.capitalone.com/browse/$1",
})
config.hyperlink_rules = link_rules
return config