-
Notifications
You must be signed in to change notification settings - Fork 0
/
.wezterm.lua
254 lines (229 loc) · 7.45 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
-- Pull in the wezterm API
local wezterm = require 'wezterm'
local act = wezterm.action
-- This will hold the configuration.
local config = wezterm.config_builder()
config.set_environment_variables = {
PATH = '/opt/homebrew/bin:' .. os.getenv 'PATH',
}
config.color_scheme = 'Tokyo Night'
-- Slightly transparent and blurred background
config.window_background_opacity = 0.9
config.macos_window_background_blur = 30
-- Removes the title bar, leaving only the tab bar. Keeps
-- the ability to resize by dragging the window's edges.
-- On macOS, 'RESIZE|INTEGRATED_BUTTONS' also looks nice if
-- you want to keep the window controls visible and integrate
-- them into the tab bar.
config.window_decorations = 'RESIZE|INTEGRATED_BUTTONS'
-- Sets the font for the window frame (tab bar)
config.window_frame = {
-- Berkeley Mono for me again, though an idea could be to try a
-- serif font here instead of monospace for a nicer look?
font = wezterm.font { family = 'JetBrains Mono', weight = 'Bold' },
font_size = 12,
}
-- config.window_background_image = "/Users/sean/Documents/backgrounds/eva-3.jpg"
config.window_background_image_hsb = {
-- Darken the background image by reducing it to 1/3rd
brightness = 0.3,
-- You can adjust the hue by scaling its value.
-- a multiplier of 1.0 leaves the value unchanged.
hue = 1.0,
-- You can adjust the saturation also.
saturation = 1.0,
}
config.window_padding = {
left = '0.5cell',
right = '0.5cell',
top = '1.0cell',
bottom = '0',
}
config.tab_bar_at_bottom = true
-- disable ligatures
config.font = wezterm.font {
family = 'JetBrains Mono',
weight = 'Medium',
harfbuzz_features = { 'calt=0', 'clig=0', 'liga=0' },
}
config.leader = { key = 'b', mods = 'CTRL', timeout_milliseconds = 1000 }
local function is_vim(pane)
-- this is set by the plugin, and unset on ExitPre in Neovim
return pane:get_user_vars().IS_NVIM == 'true'
end
local direction_keys = {
Left = 'h',
Down = 'j',
Up = 'k',
Right = 'l',
-- reverse lookup
h = 'Left',
j = 'Down',
k = 'Up',
l = 'Right',
}
local function split_nav(resize_or_move, key)
return {
key = key,
mods = resize_or_move == 'resize' and 'META' or 'CTRL',
action = wezterm.action_callback(function(win, pane)
if is_vim(pane) then
-- pass the keys through to vim/nvim
win:perform_action({
SendKey = { key = key, mods = resize_or_move == 'resize' and 'META' or 'CTRL' },
}, pane)
else
if resize_or_move == 'resize' then
win:perform_action({ AdjustPaneSize = { direction_keys[key], 3 } }, pane)
else
win:perform_action({ ActivatePaneDirection = direction_keys[key] }, pane)
end
end
end),
}
end
config.keys = {
{ key = 'LeftArrow', mods = 'CMD', action = act.ActivateTabRelative(-1) },
{ key = 'RightArrow', mods = 'CMD', action = act.ActivateTabRelative(1) },
-- Make Option-Left equivalent to Alt-b which many line editors interpret as backward-word
{ key = 'LeftArrow', mods = 'OPT', action = act.SendString '\x1bb' },
-- Make Option-Right equivalent to Alt-f; forward-word
{ key = 'RightArrow', mods = 'OPT', action = act.SendString '\x1bf' },
-- splitting
{
mods = 'LEADER',
key = '-',
action = wezterm.action.SplitVertical { domain = 'CurrentPaneDomain' },
},
{
mods = 'LEADER',
key = '=',
action = wezterm.action.SplitHorizontal { domain = 'CurrentPaneDomain' },
},
{
mods = 'LEADER',
key = 'm',
action = wezterm.action.TogglePaneZoomState,
},
-- rotate panes
{
mods = 'LEADER',
key = 'Space',
action = wezterm.action.RotatePanes 'Clockwise',
},
-- show the pane selection mode, but have it swap the active and selected panes
{
mods = 'LEADER',
key = '0',
action = wezterm.action.PaneSelect {
mode = 'SwapWithActive',
},
},
{
key = 'k',
mods = 'CMD',
action = act.ClearScrollback 'ScrollbackAndViewport',
},
{
key = ',',
mods = 'SUPER',
action = wezterm.action.SpawnCommandInNewTab {
cwd = wezterm.home_dir,
args = { 'nvim', wezterm.config_file },
},
},
-- move between split panes
split_nav('move', 'h'),
split_nav('move', 'j'),
split_nav('move', 'k'),
split_nav('move', 'l'),
-- resize panes
split_nav('resize', 'h'),
split_nav('resize', 'j'),
split_nav('resize', 'k'),
split_nav('resize', 'l'),
{
key = 'c',
mods = 'CMD',
action = wezterm.action_callback(function(window, pane)
if pane:is_alt_screen_active() then
window:perform_action(wezterm.action.SendKey { key = 'y', mods = 'CMD' }, pane)
else
window:perform_action(wezterm.action { CopyTo = 'ClipboardAndPrimarySelection' }, pane)
end
end),
},
}
for i = 1, 8 do
-- CTRL+ALT + number to move to that position
table.insert(config.keys, {
key = tostring(i),
mods = 'CTRL|ALT',
action = wezterm.action.MoveTab(i - 1),
})
end
local function segments_for_right_status(window)
return {
window:active_workspace(),
wezterm.strftime '%a %b %-d %H:%M',
wezterm.hostname(),
}
end
local function is_dark()
-- wezterm.gui is not always available, depending on what
-- environment wezterm is operating in. Just return true
-- if it's not defined.
if wezterm.gui then
-- Some systems report appearance like "Dark High Contrast"
-- so let's just look for the string "Dark" and if we find
-- it assume appearance is dark.
return wezterm.gui.get_appearance():find 'Dark'
end
return true
end
wezterm.on('update-status', function(window, _)
local SOLID_LEFT_ARROW = utf8.char(0xe0b2)
local segments = segments_for_right_status(window)
local color_scheme = window:effective_config().resolved_palette
-- Note the use of wezterm.color.parse here, this returns
-- a Color object, which comes with functionality for lightening
-- or darkening the colour (amongst other things).
local bg = wezterm.color.parse(color_scheme.background)
local fg = color_scheme.foreground
-- Each powerline segment is going to be coloured progressively
-- darker/lighter depending on whether we're on a dark/light colour
-- scheme. Let's establish the "from" and "to" bounds of our gradient.
local gradient_to, gradient_from = bg
if is_dark() then
gradient_from = gradient_to:lighten(0.2)
else
gradient_from = gradient_to:darken(0.2)
end
-- Yes, WezTerm supports creating gradients, because why not?! Although
-- they'd usually be used for setting high fidelity gradients on your terminal's
-- background, we'll use them here to give us a sample of the powerline segment
-- colours we need.
local gradient = wezterm.color.gradient(
{
orientation = 'Horizontal',
colors = { gradient_from, gradient_to },
},
#segments -- only gives us as many colours as we have segments.
)
-- We'll build up the elements to send to wezterm.format in this table.
local elements = {}
for i, seg in ipairs(segments) do
local is_first = i == 1
if is_first then
table.insert(elements, { Background = { Color = 'none' } })
end
table.insert(elements, { Foreground = { Color = gradient[i] } })
table.insert(elements, { Text = SOLID_LEFT_ARROW })
table.insert(elements, { Foreground = { Color = fg } })
table.insert(elements, { Background = { Color = gradient[i] } })
table.insert(elements, { Text = ' ' .. seg .. ' ' })
end
window:set_right_status(wezterm.format(elements))
end)
-- and finally, return the configuration to wezterm
return config