107 lines
2.8 KiB
Lua
107 lines
2.8 KiB
Lua
local wezterm = require 'wezterm'
|
|
local config = wezterm.config_builder()
|
|
|
|
-- sets fish as defualt shell
|
|
config.default_prog = { 'fish', '-l' }
|
|
|
|
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',
|
|
background = '#000000'
|
|
}
|
|
|
|
-- 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 = '#e0e0e0' },
|
|
window_background_image = wezterm.config_dir .. '/texture.png',
|
|
window_background_opacity = 1.0,
|
|
},
|
|
solid = {
|
|
colors = { foreground = '#dddddd', background = '#000000' },
|
|
window_background_opacity = 1.0,
|
|
},
|
|
}
|
|
|
|
-- 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
|