dotfiles/.config/wezterm/wezterm.lua

158 lines
5 KiB
Lua

local wezterm = require("wezterm")
local config = {}
if wezterm.config_builder then
config = wezterm.config_builder()
end
local function env_number(name, fallback)
local raw = os.getenv(name)
local parsed = raw and tonumber(raw) or nil
if parsed == nil then
return fallback
end
return parsed
end
-- User-tunable settings live in ~/.zshrc, which writes them to a cache file
-- (GUI-launched WezTerm never sees shell exports). WezTerm watches that
-- file and live-reloads, so editing .zshrc + opening a new shell applies.
-- Precedence: cache file > process env > defaults.
local user = {}
local env_file = wezterm.home_dir .. "/.cache/dotfiles/wezterm-env.lua"
local ok, loaded = pcall(dofile, env_file)
if ok and type(loaded) == "table" then
user = loaded
end
wezterm.add_to_config_reload_watch_list(env_file)
-- Basic settings
config.automatically_reload_config = true
config.window_close_confirmation = "NeverPrompt"
config.adjust_window_size_when_changing_font_size = false
config.window_decorations = "RESIZE"
config.check_for_updates = false
config.use_fancy_tab_bar = false
config.tab_bar_at_bottom = false
config.enable_tab_bar = false
-- Font configuration
config.font_size = user.font_size or env_number("WEZTERM_FONT_SIZE", 16)
config.font = wezterm.font("JetBrainsMono Nerd Font", { weight = "Regular" })
config.bold_brightens_ansi_colors = true
config.force_reverse_video_cursor = false
-- Kanagawa palette, variant chosen by $WEZTERM_THEME (set by .zshrc from
-- $KANAGAWA_THEME). Defaults to "wave"; falls back to "dragon" for anything else.
local themes = {
wave = {
foreground = "#dcd7ba",
background = "#1f1f28",
cursor_bg = "#c8c093",
cursor_fg = "#1f1f28",
cursor_border = "#c8c093",
selection_fg = "#c8c093",
selection_bg = "#2d4f67",
ansi = {
"#090618",
"#c34043",
"#76946a",
"#c0a36e",
"#7e9cd8",
"#957fb8",
"#6a9589",
"#c8c093",
},
brights = {
"#727169",
"#e82424",
"#98bb6c",
"#e6c384",
"#7fb4ca",
"#938aa9",
"#7aa89f",
"#dcd7ba",
},
},
dragon = {
foreground = "#c5c9c5",
background = "#181616",
cursor_bg = "#c5c9c5",
cursor_fg = "#181616",
cursor_border = "#c5c9c5",
selection_fg = "#c5c9c5",
selection_bg = "#2d4f67",
ansi = {
"#0d0c0c",
"#c4746e",
"#87a987",
"#c4b28a",
"#8ba4b0",
"#a292a3",
"#8ea4a2",
"#c5c9c5",
},
brights = {
"#727169",
"#e46876",
"#8a9a7b",
"#c0a36e",
"#7fb4ca",
"#938aa9",
"#7aa89f",
"#c5c9c5",
},
},
}
local variant = (user.theme or os.getenv("WEZTERM_THEME") or "wave"):lower()
if variant == "kanagawa-wave" then variant = "wave" end
if variant == "kanagawa-dragon" then variant = "dragon" end
config.colors = themes[variant] or themes.wave
-- Window padding
config.window_padding = {
left = 8,
right = 8,
top = 8,
bottom = 8,
}
-- Window transparency
config.window_background_opacity = user.window_opacity or env_number("WEZTERM_WINDOW_OPACITY", 0.80)
-- Keep text cells opaque by default; transparent text backgrounds can show
-- grid/dot artifacts on some GPU/compositor combinations.
config.text_background_opacity = user.text_opacity or env_number("WEZTERM_TEXT_OPACITY", 1.0)
-- Performance
config.scrollback_lines = 10000
config.enable_scroll_bar = false
-- Cursor
config.default_cursor_style = "BlinkingBar"
config.cursor_blink_rate = 500
config.cursor_blink_ease_in = "Constant"
config.cursor_blink_ease_out = "Constant"
-- Key bindings
config.keys = {
{ key = "Enter", mods = "CTRL", action = wezterm.action({ SendString = "\x1b[13;5u" }) },
{ key = "Enter", mods = "SHIFT", action = wezterm.action({ SendString = "\x1b[13;2u" }) },
-- Navigate splits
{ key = "h", mods = "CTRL|SHIFT", action = wezterm.action.ActivatePaneDirection("Left") },
{ key = "l", mods = "CTRL|SHIFT", action = wezterm.action.ActivatePaneDirection("Right") },
{ key = "k", mods = "CTRL|SHIFT", action = wezterm.action.ActivatePaneDirection("Up") },
{ key = "j", mods = "CTRL|SHIFT", action = wezterm.action.ActivatePaneDirection("Down") },
-- Split panes
{ key = "|", mods = "CTRL|SHIFT", action = wezterm.action.SplitHorizontal({ domain = "CurrentPaneDomain" }) },
{ key = "_", mods = "CTRL|SHIFT", action = wezterm.action.SplitVertical({ domain = "CurrentPaneDomain" }) },
-- Close pane
{ key = "w", mods = "CTRL|SHIFT", action = wezterm.action.CloseCurrentPane({ confirm = false }) },
-- Zoom pane
{ key = "z", mods = "CTRL|SHIFT", action = wezterm.action.TogglePaneZoomState },
{ key = "f", mods = "SHIFT|CTRL", action = wezterm.action.ToggleFullScreen },
}
-- Hyperlink rules
config.hyperlink_rules = {
{ regex = "\\((\\w+://\\S+)\\)", format = "$1", highlight = 1 },
{ regex = "\\[(\\w+://\\S+)\\]", format = "$1", highlight = 1 },
{ regex = "\\{(\\w+://\\S+)\\}", format = "$1", highlight = 1 },
{ regex = "<(\\w+://\\S+)>", format = "$1", highlight = 1 },
{ regex = "[^(]\\b(\\w+://\\S+[)/a-zA-Z0.9-]+)", format = "$1", highlight = 1 },
{ regex = "\\b\\w+@[\\w-]+(\\.[\\w-]+)+\\b", format = "mailto:$0" },
}
-- Window size
config.initial_rows = 34
config.initial_cols = 135
return config