-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.wezterm.lua
316 lines (278 loc) · 7.34 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
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
-- Pull in the wezterm API
local wezterm = require("wezterm")
local act = wezterm.action
local mux = wezterm.mux
--- @param s string
--- @return string
local function basename(s)
if s == "/" then
return s
end
if string.find(s, "^file://") == nil then
local res = string.match(s, ".-([^/]+)/$")
if res then
return res
end
end
local str = string.gsub(s, "file://[^/]*", "")
local dirName = string.match(str, "/([^/]+)/?$")
return dirName or s
end
--- @param workspace string
--- @param cwd string
--- @return string[]
local function set_dir(workspace, cwd)
return {
workspace = workspace,
cwd = cwd,
}
end
wezterm.on("gui-startup", function()
local dotfiles_tab, dotfiles_pane, dev_window = mux.spawn_window(set_dir("dev", wezterm.home_dir .. "/.dotfiles"))
dotfiles_pane:send_text("nvim\n")
dev_window:gui_window():toggle_fullscreen()
dev_window:spawn_tab({
cwd = wezterm.home_dir .. "/dev/watercooler-labs/toggl-cli",
})
dev_window:spawn_tab({
cwd = wezterm.home_dir .. "/dev/shantanuraj/podcst-web",
})
dev_window:spawn_tab({
cwd = wezterm.home_dir .. "/dev/shantanuraj/sraj.me",
})
dotfiles_tab:activate()
local app_tab, app_pane, work_window =
mux.spawn_window(set_dir("REKKI", wezterm.home_dir .. "/dev/rekki/buyer-app"))
app_pane:send_text("nvim\n")
app_pane:split({})
local _, api_pane, _ = work_window:spawn_tab(set_dir("REKKI", wezterm.home_dir .. "/dev/rekki/go"))
api_pane:send_text("nvim\n")
api_pane:split({
cwd = wezterm.home_dir .. "/dev/rekki/go",
})
app_tab:activate()
end)
wezterm.on("update-status", function(window)
local workspace = window:active_workspace()
local date = wezterm.strftime("%a %b %-d %H:%M")
window:set_right_status(workspace .. " | " .. date)
end)
--- trim_prefix returns s with the prefix removed.
--- @param s string
--- @param prefix string
--- @return string
local function trim_prefix(s, prefix)
local len = #s
local plen = #prefix
if len == 0 or plen == 0 or len < plen then
return s
elseif s == prefix then
return ""
elseif string.sub(s, 1, plen) == prefix then
-- remove prefix
return string.sub(s, plen + 1)
end
return s
end
wezterm.on("format-tab-title", function(tab)
local pane = tab.active_pane
if pane.current_working_dir == nil then
return " " .. pane.title .. " "
end
local title = basename(pane.current_working_dir.file_path) or ""
if title == "" and pane.domain_name then
title = trim_prefix(pane.domain_name, "SSH to ") .. ":" .. basename(pane.title)
end
title = trim_prefix(title, "local:")
if pane.is_zoomed then
title = title .. " +"
end
return {
{ Text = " " .. title .. " " },
}
end)
wezterm.on("user-var-changed", function(window, pane, name, value)
local overrides = window:get_config_overrides() or {}
if name == "ZEN_MODE" then
local incremental = value:find("+")
local number_value = tonumber(value)
if incremental ~= nil then
while number_value > 0 do
window:perform_action(wezterm.action.IncreaseFontSize, pane)
number_value = number_value - 1
end
overrides.enable_tab_bar = false
elseif number_value < 0 then
window:perform_action(wezterm.action.ResetFontSize, pane)
overrides.font_size = nil
overrides.enable_tab_bar = true
else
overrides.font_size = number_value
overrides.enable_tab_bar = false
end
end
window:set_config_overrides(overrides)
end)
local function get_appearance()
if wezterm.gui then
return wezterm.gui.get_appearance()
end
return "Dark"
end
local function color_scheme_for_appearance(appearance)
if appearance:find("Dark") then
return "zenbones_dark"
else
return "zenbones"
end
end
wezterm.on("window-config-reloaded", function(window)
local overrides = window:get_config_overrides() or {}
local appearance = "Dark"
local color_scheme = color_scheme_for_appearance(appearance)
if overrides.color_scheme ~= color_scheme then
overrides.color_scheme = color_scheme
window:set_config_overrides(overrides)
end
end)
local config = {}
if wezterm.config_builder then
config = wezterm.config_builder()
end
config.initial_cols = 160
config.initial_rows = 48
config.default_prog = { "/bin/zsh", "-l" }
config.color_scheme = color_scheme_for_appearance(get_appearance())
config.default_workspace = "dev"
config.font = wezterm.font("Berkeley Mono")
config.term = "wezterm"
config.font_size = 14.0
config.use_fancy_tab_bar = false
config.tab_bar_at_bottom = true
config.tab_max_width = 24
config.show_tab_index_in_tab_bar = false
config.show_new_tab_button_in_tab_bar = false
config.window_frame = {
font_size = 14.0,
-- active_titlebar_bg = "#12131d",
-- inactive_titlebar_bg = "#1e2030",
}
config.window_padding = {
left = 0,
right = 0,
top = 0,
bottom = 0,
}
config.bold_brightens_ansi_colors = true
config.keys = {
{
key = "w",
mods = "SUPER",
action = act.ShowLauncherArgs({
flags = "FUZZY|WORKSPACES",
}),
},
{
key = "l",
mods = "SUPER|SHIFT",
action = act.SwitchWorkspaceRelative(1),
},
{
key = "r",
mods = "SUPER|SHIFT",
action = act.RotatePanes("Clockwise"),
},
{
key = "f",
mods = "SUPER|SHIFT",
action = act.QuickSelect,
},
{
key = "f",
mods = "SUPER",
action = act.Search("CurrentSelectionOrEmptyString"),
},
{
key = "g",
mods = "SUPER",
action = act.ActivateCopyMode,
},
{ key = "a", mods = "ALT", action = act.ShowLauncher },
{ key = " ", mods = "ALT", action = act.ShowTabNavigator },
{ mods = "SUPER", key = "d", action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }) },
{ mods = "SUPER|SHIFT", key = "d", action = act.SplitVertical({ domain = "CurrentPaneDomain" }) },
{ key = "[", mods = "SUPER", action = act.ActivatePaneDirection("Prev") },
{ key = "]", mods = "SUPER", action = act.ActivatePaneDirection("Next") },
-- maxmize current pane
{
key = "Enter",
mods = "SUPER|SHIFT",
action = act.TogglePaneZoomState,
},
{ key = "UpArrow", mods = "SHIFT", action = act.ScrollToPrompt(-1) },
{ key = "DownArrow", mods = "SHIFT", action = act.ScrollToPrompt(1) },
}
config.mouse_bindings = {
{
event = { Down = { streak = 3, button = "Left" } },
action = act.SelectTextAtMouseCursor("SemanticZone"),
mods = "NONE",
},
}
--- @generic T
--- @param dst T[]
--- @param ... T[]
--- @return T[]
local function list_extend(dst, ...)
for _, list in ipairs({ ... }) do
for _, v in ipairs(list) do
table.insert(dst, v)
end
end
return dst
end
local accept_pattern = {
Multiple = {
{ CopyMode = "ClearSelectionMode" },
{ CopyMode = "AcceptPattern" },
},
}
local clear_pattern = {
Multiple = {
{ CopyMode = "ClearPattern" },
{ CopyMode = "ClearSelectionMode" },
{ CopyMode = "AcceptPattern" },
},
}
local key_tables = wezterm.gui.default_key_tables()
list_extend(key_tables.copy_mode, {
{ key = "/", action = { Search = { CaseInSensitiveString = "" } } },
{ key = "n", action = { CopyMode = "NextMatch" } },
{ key = "n", mods = "SHIFT", action = { CopyMode = "PriorMatch" } },
{ key = "c", mods = "CTRL", action = clear_pattern },
{
key = "y",
action = {
Multiple = {
{ CopyTo = "PrimarySelection" },
{ CopyMode = "Close" },
},
},
},
{
key = "[",
mods = "NONE",
action = act.CopyMode("MoveBackwardSemanticZone"),
},
{
key = "]",
mods = "NONE",
action = act.CopyMode("MoveForwardSemanticZone"),
},
})
list_extend(key_tables.search_mode, {
{ key = "Enter", action = accept_pattern },
{ key = "c", mods = "CTRL", action = clear_pattern },
})
config.key_tables = key_tables
return config