-
Notifications
You must be signed in to change notification settings - Fork 0
/
wezterm.lua
264 lines (228 loc) · 11.3 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
-- https://wezfurlong.org/wezterm/config/lua/keyassignment/
-- https://wezfurlong.org/wezterm/config/default-keys.html
-- https://github.com/yutkat/dotfiles/tree/main/.config/wezterm
-- https://github.com/KevinSilvester/wezterm-config
-- https://github.com/mrjones2014/smart-splits.nvim#wezterm
-- https://github.com/wez/wezterm/discussions/2329
-- NOTE: environment variable WEZTERM_CONFIG_DIR should point to this file
local wezterm = require 'wezterm'
local workspace_sessionizer = require 'workspace_sessionizer'
local utils = require 'utils'
local platform = require 'platform'
local act = wezterm.action
local mux = wezterm.mux
local io = require 'io'
local os = require 'os'
local zettelkasten = wezterm.home_dir .. '/src/zettelkasten/'
-- Troubleshooting
-- https://wezfurlong.org/wezterm/troubleshooting.html
-- Allow working with both the current release and the nightly
local config = {}
if wezterm.config_builder then
config = wezterm.config_builder()
end
-- https://wezfurlong.org/wezterm/config/fonts.html
-- https://www.jetbrains.com/lp/mono/
-- https://github.com/microsoft/cascadia-code
-- https://github.com/tonsky/FiraCode
-- https://github.com/adobe-fonts/source-code-pro
config.font_size = 12
-- config.disable_default_key_bindings = true
config.hide_tab_bar_if_only_one_tab = true
-- https://wezfurlong.org/wezterm/config/lua/config/debug_key_events.html
config.debug_key_events = false
-- config.color_scheme = 'AdventureTime'
-- config.color_scheme = 'rose-pine'
-- config.color_scheme = 'Dracula (Gogh)'
-- config.color_scheme = 'Gruvbox (Gogh)'
-- config.color_scheme = 'Gruvbox Dark (Gogh)'
wezterm.on('gui-startup', function()
local _, _, window = mux.spawn_window {}
window:gui_window():maximize()
end)
-- https://wezfurlong.org/wezterm/faq.html?h=path#im-on-macos-and-wezterm-cannot-find-things-in-my-path
if platform.is_mac then
config.set_environment_variables = {
PATH = table.concat({
wezterm.home_dir .. '/.cargo/bin',
wezterm.home_dir .. '/bin',
os.getenv 'PATH',
}, ':'),
-- prepend the path to custom binaries
}
end
local launch_menu = {}
if platform.is_win then
-- wezterm.log_info 'on windows'
config.default_prog = { wezterm.home_dir .. '/bin/nu' }
launch_menu = {
{ label = 'PowerShell Core', args = { 'pwsh' } },
{ label = 'PowerShell Desktop', args = { 'powershell' } },
{ label = 'Command Prompt', args = { 'cmd' } },
{ label = 'Nushell', args = { wezterm.home_dir .. '/bin/nu' } },
}
else
-- wezterm.log_info 'on mac or linux'
config.default_prog = { wezterm.home_dir .. '/bin/nu' }
launch_menu = {
{ label = 'Bash', args = { 'bash' } },
{ label = 'Nushell', args = { wezterm.home_dir .. '/bin/nu' } },
{ label = 'Zsh', args = { 'zsh' } },
}
end
config.launch_menu = launch_menu
-- Styling Inactive Panes
config.inactive_pane_hsb = {
saturation = 0.5, -- smaller values can make it appear more washed out
brightness = 0.8, -- dims or increases the perceived amount of light
}
-- https://wezfurlong.org/wezterm/config/lua/wezterm/on.html#custom-events
wezterm.on('trigger-nvim-with-scrollback', function(window, pane)
-- Retrieve the text from the pane
local text = pane:get_lines_as_text(pane:get_dimensions().scrollback_rows)
-- Create a temporary file to pass to vim
local name = os.tmpname()
local f = io.open(name, 'w+')
if f == nil then
wezterm.log_error('failed to open ' .. name)
return
end
f:write(text)
f:flush()
f:close()
window:perform_action(act.SplitHorizontal { args = { 'nu', '-e', 'nvim ' .. name } }, pane)
-- Wait "enough" time for vim to read the file before we remove it.
-- The window creation and process spawn are asynchronous wrt. running
-- this script and are not awaitable, so we just pick a number.
--
-- Note: We don't strictly need to remove this file, but it is nice
-- to avoid cluttering up the temporary directory.
wezterm.sleep_ms(1000)
os.remove(name)
end)
config.mouse_bindings = {
-- -- https://dystroy.org/blog/from-terminator-to-wezterm/
-- -- Disable the default click behavior
-- {
-- event = { Up = { streak = 1, button = 'Left' } },
-- mods = 'NONE',
-- action = w.action.DisableDefaultAssignment,
-- },
-- -- Ctrl-click will open the link under the mouse cursor
-- {
-- event = { Up = { streak = 1, button = 'Left' } },
-- mods = 'CTRL',
-- action = w.action.OpenLinkAtMouseCursor,
-- },
-- -- Disable the Ctrl-click down event to stop programs from seeing it when a URL is clicked
-- {
-- event = { Down = { streak = 1, button = 'Left' } },
-- mods = 'CTRL',
-- action = w.action.Nop,
-- },
{
event = { Down = { streak = 3, button = 'Left' } },
action = wezterm.action.SelectTextAtMouseCursor 'SemanticZone',
mods = 'NONE',
},
}
config.keys = {
{ key = '0', mods = 'ALT', action = wezterm.action.ResetFontSize },
{ key = 'z', mods = 'ALT', action = act.TogglePaneZoomState },
-- { key = 'd', mods = 'ALT', action = act.DisableDefaultAssignment }, -- don't remember why
-- fix ctrl-space not reaching the term https://github.com/wez/wezterm/issues/4055#issuecomment-1694542317
{ key = ' ', mods = 'CTRL', action = act.SendKey { key = ' ', mods = 'CTRL' } },
-- { key = '^', mods = "NONE", action = act.SendKey { key = '6', mods = mods.shift_ctrl } },
-- Main bidings
{ key = 'F12', mods = 'NONE', action = act.ShowDebugOverlay },
{ key = '-', mods = 'ALT', action = act { SplitVertical = { domain = 'CurrentPaneDomain' } } },
{ key = 'v', mods = 'ALT', action = act { SplitVertical = { domain = 'CurrentPaneDomain' } } },
{ key = '\\', mods = 'ALT', action = act { SplitHorizontal = { domain = 'CurrentPaneDomain' } } },
{ key = 's', mods = 'ALT', action = act { SplitHorizontal = { domain = 'CurrentPaneDomain' } } },
{ key = 'a', mods = 'ALT', action = act.ActivateCommandPalette }, -- [c]ommands
{ key = 'c', mods = 'ALT', action = act.ActivateCopyMode }, -- [C]opy
{ key = 'd', mods = 'ALT', action = act.ShowDebugOverlay },
{ key = 'f', mods = 'ALT', action = act.Search { CaseInSensitiveString = '' } }, -- [f]ind
{ key = 'r', mods = 'ALT', action = act.RotatePanes 'Clockwise' }, -- [r]otate panes
{ key = 'r', mods = 'CTRL|ALT', action = act.RotatePanes 'CounterClockwise' }, -- [r]otate panes counter clockwise
{ key = 'w', mods = 'ALT', action = act.PaneSelect { mode = 'SwapWithActive' } }, -- [s]wap pane with another one
{ key = 'u', mods = 'ALT', action = act.CharSelect }, -- insert [u]nicode character, e.g. emoji
-- Workspaces (alt + shift)
{ key = 'D', mods = 'ALT|SHIFT', action = act.SwitchToWorkspace { name = 'default' } }, -- switch to the [d]efault workspace
{ key = 'A', mods = 'ALT|SHIFT', action = act.SwitchToWorkspace }, -- [a]dd a new workspace with a random name and switch to it
{ key = 'W', mods = 'ALT|SHIFT', action = act.ShowLauncherArgs { flags = 'FUZZY|WORKSPACES' } }, -- fuzzy search or create new [w]orkspace
{ key = 'N', mods = 'ALT|SHIFT', action = act.SwitchWorkspaceRelative(1) }, -- [n]ext
{ key = 'P', mods = 'ALT|SHIFT', action = act.SwitchWorkspaceRelative(-1) }, -- [p]revious
{ key = 'S', mods = 'ALT|SHIFT', action = wezterm.action_callback(workspace_sessionizer.start) }, -- open new session
{ key = 'B', mods = 'ALT|SHIFT', action = wezterm.action.ToggleAlwaysOnBottom },
{ key = 'T', mods = 'ALT|SHIFT', action = wezterm.action.ToggleAlwaysOnTop },
-- https://wezfurlong.org/wezterm/config/lua/keyassignment/ScrollToPrompt.html
-- This action operates on Semantic Zones defined by applications that use OSC 133 Semantic Prompt Escapes and requires configuring your shell to emit those sequences.
-- OSC 133 escapes allow marking regions of output as Output (from the commands that you run), Input (that you type) and Prompt ("chrome" from your shell).
-- { key = 'UpArrow', mods = 'SHIFT', action = act.ScrollToPrompt(-1) },
-- { key = 'DownArrow', mods = 'SHIFT', action = act.ScrollToPrompt(1) },
-- open config file
{
key = ',',
mods = 'ALT',
action = act.SwitchToWorkspace {
name = 'wezterm-config',
spawn = {
cwd = os.getenv 'WEZTERM_CONFIG_DIR',
args = { 'nu', '-e', 'nvim $env.WEZTERM_CONFIG_FILE' },
},
},
},
-- Window
{ key = 'F11', mods = 'NONE', action = act.ToggleFullScreen },
{ key = 'Enter', mods = 'ALT', action = act.DisableDefaultAssignment }, -- broot uses alt-enter
-- adjust panes
{ key = 'H', mods = 'ALT|SHIFT', action = act.AdjustPaneSize { 'Left', 3 } },
{ key = 'L', mods = 'ALT|SHIFT', action = act.AdjustPaneSize { 'Right', 3 } },
{ key = 'J', mods = 'ALT|SHIFT', action = act.AdjustPaneSize { 'Down', 3 } },
{ key = 'K', mods = 'ALT|SHIFT', action = act.AdjustPaneSize { 'Up', 3 } },
{ key = 'h', mods = 'ALT', action = act.ActivatePaneDirection 'Left' },
{ key = 'j', mods = 'ALT', action = act.ActivatePaneDirection 'Down' },
{ key = 'k', mods = 'ALT', action = act.ActivatePaneDirection 'Up' },
{ key = 'l', mods = 'ALT', action = act.ActivatePaneDirection 'Right' },
{ key = 'x', mods = 'ALT', action = act.CloseCurrentPane { confirm = true } }, -- forced close pane
{ key = 'q', mods = 'ALT', action = act.CloseCurrentPane { confirm = false } }, -- forced close pane
{ key = 'n', mods = 'ALT', action = act.ActivatePaneDirection 'Next' },
{ key = 'p', mods = 'ALT', action = act.ActivatePaneDirection 'Prev' },
-- Cli apps
-- lagy[g]it
{ key = 'g', mods = 'ALT', action = act.SplitHorizontal { args = { 'nu', '-e', 'lazygit' } } },
{ key = 'g', mods = 'CTRL|ALT', action = act.SplitVertical { args = { 'nu', '-e', 'lazygit' } } },
-- open broot, alt-x to close pane, ctrl-c to go back to shell
{ key = 'b', mods = 'ALT', action = act.SplitHorizontal { args = { 'nu', '-e', 'br' } } },
{ key = 'b', mods = 'CTRL|ALT', action = act.SplitVertical { args = { 'nu', '-e', 'br' } } },
{ key = 't', mods = 'ALT', action = act.SplitVertical { cwd = zettelkasten, args = { 'nu', '-e', 'nvim ' .. zettelkasten .. 'todos.md' } } },
{ key = 't', mods = 'CTRL|ALT', action = act.SplitVertical { cwd = zettelkasten, args = { 'nu', '-e', 'nvim ' .. zettelkasten .. 'todos.md' } } },
{ key = 'e', mods = 'ALT', action = act.EmitEvent 'trigger-nvim-with-scrollback' },
--m[o]nitoring
{ key = 'm', mods = 'ALT', action = act.SplitVertical { args = { 'btm' } } },
{ key = 'm', mods = 'CTRL|ALT', action = act.SplitHorizontal { args = { 'btm' } } },
}
config.switch_to_last_active_tab_when_closing_tab = true
config.exit_behavior = 'CloseOnCleanExit'
config.hyperlink_rules = {
-- Matches: a URL in parens: (URL)
{ regex = '\\((\\w+://\\S+)\\)', format = '$1', highlight = 1 },
-- Matches: a URL in brackets: [URL]
{ regex = '\\[(\\w+://\\S+)\\]', format = '$1', highlight = 1 },
-- Matches: a URL in curly braces: {URL}
{ regex = '\\{(\\w+://\\S+)\\}', format = '$1', highlight = 1 },
-- Matches: a URL in angle brackets: <URL>
{ regex = '<(\\w+://\\S+)>', format = '$1', highlight = 1 },
-- Matches: numbers
-- {
-- regex = '(\\d+)',
-- format = 'https://mbbm-ast.visualstudio.com/AST/_workitems/edit/$1',
-- highlight = 1,
-- },
-- Then handle URLs not wrapped in brackets
{ regex = '[^(]\\b(\\w+://\\S+[)/a-zA-Z0-9-]+)', format = '$1', highlight = 1 },
-- implicit mailto link
{ regex = '\\b\\w+@[\\w-]+(\\.[\\w-]+)+\\b', format = 'mailto:$0', highlight = 1 },
}
return config