Files
nix-config/home/Winter/common/features/wezterm/wezterm.lua
T

111 lines
3.0 KiB
Lua

local wezterm = require 'wezterm'
local config = wezterm.config_builder()
-- Launch fish directly instead of your system login shell
config.default_prog = { 'fish', '-l' }
-- Base Appearance & Tab Bar (Default / Fallback state)
config.window_background_opacity = 0.60
config.wayland_window_background_blur = true
config.hide_tab_bar_if_only_one_tab = true
config.window_padding = {
left = 0,
right = 0,
top = 0,
bottom = 0,
}
config.font_size = 14.0
config.colors = {
foreground = '#dddddd',
}
-- Helper to safely check if a file exists before applying it
local function file_exists(path)
if not path then
return false
end
local f = io.open(path, 'r')
if f then
f:close()
return true
end
return false
end
-- Define arbitrary theme profiles here.
-- Keys correspond to the value of the WEZTERM_THEME user variable.
local profiles = {
nvim = {
colors = { foreground = '#ffffff' },
window_background_image = wezterm.config_dir .. '/texture.png',
window_background_opacity = 1.0,
},
solid = {
colors = { foreground = '#eeeeee', background = '#1e1e2e' },
window_background_opacity = 1.0,
},
light = {
colors = { foreground = '#111111', background = '#f5f5f5' },
window_background_opacity = 0.95,
},
}
-- Track the active profile per window so we don't trigger redundant reloads
local active_window_profiles = {}
local function sync_appearance(window, pane)
if not pane then
return
end
local user_vars = pane:get_user_vars()
local target_profile = user_vars.WEZTERM_THEME or 'default'
local win_id = window:window_id()
-- Skip if this window is already using the requested profile
if active_window_profiles[win_id] == target_profile then
return
end
local profile_settings = profiles[target_profile]
if profile_settings then
local overrides = {}
-- Copy arbitrary settings from the chosen profile
for key, value in pairs(profile_settings) do
overrides[key] = value
end
-- Fallback: If a background image is specified, verify the file exists.
-- If missing, drop the image override and restore base opacity so text stays readable.
if overrides.window_background_image and not file_exists(overrides.window_background_image) then
wezterm.log_warn('Background image not found: ' .. overrides.window_background_image)
overrides.window_background_image = nil
overrides.window_background_opacity = nil
end
window:set_config_overrides(overrides)
active_window_profiles[win_id] = target_profile
else
-- Reset to base config if the variable is unset, empty, or unrecognized
window:set_config_overrides({})
active_window_profiles[win_id] = 'default'
end
end
wezterm.on('user-var-changed', function(window, pane, name, _value)
if name == 'WEZTERM_THEME' then
sync_appearance(window, pane)
end
end)
-- Keep state synced when switching tabs or closing panes
wezterm.on('update-status', function(window, pane)
sync_appearance(window, pane)
end)
return config