-
Notifications
You must be signed in to change notification settings - Fork 0
/
.wezterm.lua
245 lines (223 loc) · 5.35 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
-- Dump any object to string
local function dump(o)
if type(o) == "table" then
local s = "{ "
for k, v in pairs(o) do
if type(k) ~= "number" then
k = '"' .. k .. '"'
end
s = s .. "[" .. k .. "] = " .. dump(v) .. ","
end
return s .. "} "
else
return tostring(o)
end
end
-- table union: a += b
local function table_union(a, b)
if type(a) ~= "table" or type(b) ~= "table" then
error("Illegal argument: a or b are not a 'table' type")
end
for k, v in pairs(b) do
if a[k] ~= nil then
error(string.format("Duplicate keys detected:\nkey=%q, exist value=%q", dump(k), dump(a[k])))
return
end
a[k] = v
end
end
-- Define Config class
Config = { inner = {} }
function Config:new()
local o = {}
setmetatable(o, self)
self.__index = self
self.inner = {}
return o
end
function Config:add(t)
table_union(self.inner, t)
return self
end
local wezterm = require("wezterm")
local act = wezterm.action
local gui = wezterm.gui
local function format_tabs(tab, tabs)
local mux_window = wezterm.mux.get_window(tab.window_id)
local mux_tab_cols = mux_window:active_tab():get_size().cols
local tab_count = #tabs
local inactive_tab_cols = math.floor(mux_tab_cols / tab_count)
local active_tab_cols = mux_tab_cols - (tab_count - 1) * inactive_tab_cols
local file = wezterm.mux.get_tab(tab.tab_id):active_pane():get_current_working_dir()
local file_path = nil
if file == nil then
if tab.active_pane.domain_name:match("SSH") then
file_path = tab.active_pane.title
else
file_path = " "
end
else
file_path = file.file_path
end
local title = " " .. file_path .. " "
local title_cols = wezterm.column_width(title)
local is_active = tab.is_active
local icon = is_active and " " or " "
local tab_cols = is_active and active_tab_cols or inactive_tab_cols
local remaining_cols = math.max(tab_cols - title_cols, 0)
local right_cols = math.ceil(remaining_cols / 2)
local left_cols = remaining_cols - right_cols
local is_zoomed = tab.active_pane.is_zoomed
local zoom_icon = is_zoomed and " " or " "
local elements = {
-- Left padding and icon
{ Text = wezterm.pad_right(icon, left_cols) },
-- Centered title
is_active and { Attribute = { Italic = true } } or {},
{ Text = title },
-- Right padding
{ Text = wezterm.pad_right(zoom_icon, right_cols) },
}
local formatted_elements = {}
for _, item in ipairs(elements) do
if next(item) ~= nil then
table.insert(formatted_elements, item)
end
end
return formatted_elements
end
wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width)
return format_tabs(tab, tabs)
end)
wezterm.on("user-var-changed", function(window, pane, name, value)
wezterm.log_info("var", name, value)
end)
local launch_menu = {
default_prog = { "pwsh", "--NoLogo" },
launch_menu = {
{ label = "🟣 PowerShell Core", args = { "pwsh" } },
{ label = "🔵 Windows PowerShell", args = { "powershell" } },
},
}
local appearance = {
color_scheme = "ayu",
font = wezterm.font({ family = "CaskaydiaCove Nerd Font" }),
font_size = 14.0,
window_frame = {
border_left_width = "0.25cell",
border_right_width = "0.25cell",
border_bottom_height = "0.125cell",
border_top_height = "0.125cell",
border_left_color = "#0063B1",
border_right_color = "#0063B1",
border_bottom_color = "#0063B1",
border_top_color = "#0063B1",
},
window_decorations = "RESIZE",
use_fancy_tab_bar = false,
show_new_tab_button_in_tab_bar = true,
tab_bar_at_bottom = false,
enable_scroll_bar = false,
hide_tab_bar_if_only_one_tab = false,
tab_max_width = 99999,
status_update_interval = 1000,
colors = {
tab_bar = {
active_tab = {
bg_color = "#0B0E14",
fg_color = "#CED4DF",
intensity = "Bold",
},
inactive_tab = {
bg_color = "#14171D",
fg_color = "#54575D",
intensity = "Normal",
},
inactive_tab_hover = {
bg_color = "#54575D",
fg_color = "#14171D",
},
new_tab = {
bg_color = "#14171D",
fg_color = "#FFFFFF",
},
background = "#14171D",
},
},
}
local keybinding = {
keys = {
{
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 = "s",
mods = "ALT",
action = act.SplitVertical({ domain = "CurrentPaneDomain" }),
},
{
key = "v",
mods = "ALT",
action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }),
},
{
key = "q",
mods = "ALT",
action = act.CloseCurrentPane({ confirm = true }),
},
{
key = "LeftArrow",
mods = "ALT",
action = act.AdjustPaneSize({ "Left", 1 }),
},
{
key = "RightArrow",
mods = "ALT",
action = act.AdjustPaneSize({ "Right", 1 }),
},
{
key = "UpArrow",
mods = "ALT",
action = act.AdjustPaneSize({ "Up", 1 }),
},
{
key = "DownArrow",
mods = "ALT",
action = act.AdjustPaneSize({ "Down", 1 }),
},
{
key = "z",
mods = "ALT",
action = act.TogglePaneZoomState,
},
{
key = "p",
mods = "ALT",
action = act.PasteFrom("Clipboard"),
},
},
}
local mux = {
unix_domains = { {
name = "unix",
} },
default_gui_startup_args = { "connect", "unix" },
}
return Config:new():add(launch_menu):add(appearance):add(keybinding):add(mux).inner