-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.wezterm.lua
389 lines (358 loc) · 8.87 KB
/
example.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
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
-- Pull in the wezterm API
local os = require("os")
local wezterm = require("wezterm")
local session_manager = require("wezterm-session-manager/session-manager")
local act = wezterm.action
local mux = wezterm.mux
-- --------------------------------------------------------------------
-- FUNCTIONS AND EVENT BINDINGS
-- --------------------------------------------------------------------
-- Session Manager event bindings
-- See https://github.com/danielcopper/wezterm-session-manager
wezterm.on("save_session", function(window)
session_manager.save_state(window)
end)
wezterm.on("load_session", function(window)
session_manager.load_state(window)
end)
wezterm.on("restore_session", function(window)
session_manager.restore_state(window)
end)
-- Wezterm <-> nvim pane navigation
-- You will need to install https://github.com/aca/wezterm.nvim
-- and ensure you export NVIM_LISTEN_ADDRESS per the README in that repo
local move_around = function(window, pane, direction_wez, direction_nvim)
local result = os.execute(
"env NVIM_LISTEN_ADDRESS=/tmp/nvim"
.. pane:pane_id()
.. " "
.. wezterm.home_dir
.. "/.local/bin/wezterm.nvim.navigator"
.. " "
.. direction_nvim
)
if result then
window:perform_action(act({ SendString = "\x17" .. direction_nvim }), pane)
else
window:perform_action(act({ ActivatePaneDirection = direction_wez }), pane)
end
end
wezterm.on("move-left", function(window, pane)
move_around(window, pane, "Left", "h")
end)
wezterm.on("move-right", function(window, pane)
move_around(window, pane, "Right", "l")
end)
wezterm.on("move-up", function(window, pane)
move_around(window, pane, "Up", "k")
end)
wezterm.on("move-down", function(window, pane)
move_around(window, pane, "Down", "j")
end)
local vim_resize = function(window, pane, direction_wez, direction_nvim)
local result = os.execute(
"env NVIM_LISTEN_ADDRESS=/tmp/nvim"
.. pane:pane_id()
.. " "
.. wezterm.home_dir
.. "/.local/bin/wezterm.nvim.navigator"
.. " "
.. direction_nvim
)
if result then
window:perform_action(act({ SendString = "\x1b" .. direction_nvim }), pane)
else
window:perform_action(act({ ActivatePaneDirection = direction_wez }), pane)
end
end
wezterm.on("resize-left", function(window, pane)
vim_resize(window, pane, "Left", "h")
end)
wezterm.on("resize-right", function(window, pane)
vim_resize(window, pane, "Right", "l")
end)
wezterm.on("resize-up", function(window, pane)
vim_resize(window, pane, "Up", "k")
end)
wezterm.on("resize-down", function(window, pane)
vim_resize(window, pane, "Down", "j")
end)
-- --------------------------------------------------------------------
-- CONFIGURATION
-- --------------------------------------------------------------------
-- This table will hold the configuration.
local config = {}
-- In newer versions of wezterm, use the config_builder which will
-- help provide clearer error messages
if wezterm.config_builder then
config = wezterm.config_builder()
end
config.adjust_window_size_when_changing_font_size = false
config.automatically_reload_config = true
config.color_scheme = "Solarized (dark) (terminal.sexy)"
config.enable_scroll_bar = true
config.enable_wayland = true
-- config.font = wezterm.font('Hack')
config.font = wezterm.font("Monaspace Neon")
config.font_size = 12.0
config.hide_tab_bar_if_only_one_tab = true
-- The leader is similar to how tmux defines a set of keys to hit in order to
-- invoke tmux bindings. Binding to ctrl-a here to mimic tmux
config.leader = { key = "a", mods = "CTRL", timeout_milliseconds = 2000 }
config.mouse_bindings = {
-- Open URLs with Ctrl+Click
{
event = { Up = { streak = 1, button = "Left" } },
mods = "CTRL",
action = act.OpenLinkAtMouseCursor,
},
}
config.pane_focus_follows_mouse = true
config.scrollback_lines = 5000
config.use_dead_keys = false
config.warn_about_missing_glyphs = false
config.window_decorations = "TITLE | RESIZE"
config.window_padding = {
left = 0,
right = 0,
top = 0,
bottom = 0,
}
-- Tab bar
config.use_fancy_tab_bar = true
config.tab_bar_at_bottom = true
config.switch_to_last_active_tab_when_closing_tab = true
config.tab_max_width = 32
config.colors = {
tab_bar = {
active_tab = {
fg_color = "#073642",
bg_color = "#2aa198",
},
},
}
-- Setup muxing by default
config.unix_domains = {
{
name = "unix",
},
}
-- Custom key bindings
config.keys = {
-- -- Disable Alt-Enter combination (already used in tmux to split pane)
-- {
-- key = 'Enter',
-- mods = 'ALT',
-- action = act.DisableDefaultAssignment,
-- },
-- Copy mode
{
key = "[",
mods = "LEADER",
action = act.ActivateCopyMode,
},
-- ----------------------------------------------------------------
-- TABS
--
-- Where possible, I'm using the same combinations as I would in tmux
-- ----------------------------------------------------------------
-- Show tab navigator; similar to listing panes in tmux
{
key = "w",
mods = "LEADER",
action = act.ShowTabNavigator,
},
-- Create a tab (alternative to Ctrl-Shift-Tab)
{
key = "c",
mods = "LEADER",
action = act.SpawnTab("CurrentPaneDomain"),
},
-- Rename current tab; analagous to command in tmux
{
key = ",",
mods = "LEADER",
action = act.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),
}),
},
-- Move to next/previous TAB
{
key = "n",
mods = "LEADER",
action = act.ActivateTabRelative(1),
},
{
key = "p",
mods = "LEADER",
action = act.ActivateTabRelative(-1),
},
-- Close tab
{
key = "&",
mods = "LEADER|SHIFT",
action = act.CloseCurrentTab({ confirm = true }),
},
-- ----------------------------------------------------------------
-- PANES
--
-- These are great and get me most of the way to replacing tmux
-- entirely, particularly as you can use "wezterm ssh" to ssh to another
-- server, and still retain Wezterm as your terminal there.
-- ----------------------------------------------------------------
-- -- Vertical split
{
-- |
key = "|",
mods = "LEADER|SHIFT",
action = act.SplitPane({
direction = "Right",
size = { Percent = 50 },
}),
},
-- Horizontal split
{
-- -
key = "-",
mods = "LEADER",
action = act.SplitPane({
direction = "Down",
size = { Percent = 50 },
}),
},
-- CTRL + (h,j,k,l) to move between panes
{
key = "h",
mods = "CTRL",
action = act({ EmitEvent = "move-left" }),
},
{
key = "j",
mods = "CTRL",
action = act({ EmitEvent = "move-down" }),
},
{
key = "k",
mods = "CTRL",
action = act({ EmitEvent = "move-up" }),
},
{
key = "l",
mods = "CTRL",
action = act({ EmitEvent = "move-right" }),
},
-- ALT + (h,j,k,l) to resize panes
{
key = "h",
mods = "ALT",
action = act({ EmitEvent = "resize-left" }),
},
{
key = "j",
mods = "ALT",
action = act({ EmitEvent = "resize-down" }),
},
{
key = "k",
mods = "ALT",
action = act({ EmitEvent = "resize-up" }),
},
{
key = "l",
mods = "ALT",
action = act({ EmitEvent = "resize-right" }),
},
-- Close/kill active pane
{
key = "x",
mods = "LEADER",
action = act.CloseCurrentPane({ confirm = true }),
},
-- Swap active pane with another one
{
key = "{",
mods = "LEADER|SHIFT",
action = act.PaneSelect({ mode = "SwapWithActiveKeepFocus" }),
},
-- Zoom current pane (toggle)
{
key = "z",
mods = "LEADER",
action = act.TogglePaneZoomState,
},
{
key = "f",
mods = "ALT",
action = act.TogglePaneZoomState,
},
-- Move to next/previous pane
{
key = ";",
mods = "LEADER",
action = act.ActivatePaneDirection("Prev"),
},
{
key = "o",
mods = "LEADER",
action = act.ActivatePaneDirection("Next"),
},
-- ----------------------------------------------------------------
-- Workspaces
--
-- These are roughly equivalent to tmux sessions.
-- ----------------------------------------------------------------
-- Attach to muxer
{
key = "a",
mods = "LEADER",
action = act.AttachDomain("unix"),
},
-- Detach from muxer
{
key = "d",
mods = "LEADER",
action = act.DetachDomain({ DomainName = "unix" }),
},
-- Show list of workspaces
{
key = "s",
mods = "LEADER",
action = act.ShowLauncherArgs({ flags = "WORKSPACES" }),
},
-- Rename current session; analagous to command in tmux
{
key = "$",
mods = "LEADER|SHIFT",
action = act.PromptInputLine({
description = "Enter new name for session",
action = wezterm.action_callback(function(window, pane, line)
if line then
mux.rename_workspace(window:mux_window():get_workspace(), line)
end
end),
}),
},
-- Session manager bindings
{
key = "s",
mods = "LEADER|SHIFT",
action = act({ EmitEvent = "save_session" }),
},
{
key = "L",
mods = "LEADER|SHIFT",
action = act({ EmitEvent = "load_session" }),
},
{
key = "R",
mods = "LEADER|SHIFT",
action = act({ EmitEvent = "restore_session" }),
},
}
-- and finally, return the configuration to wezterm
return config