chore: update wezterm configs and sessionizer submodule
This commit is contained in:
parent
e8d6d399af
commit
30cbf8d1c7
3 changed files with 128 additions and 73 deletions
|
|
@ -1 +1 @@
|
||||||
Subproject commit c4379654bc179c72c57693b12d16a95d21c1651d
|
Subproject commit 1c93cd8c46369c40c126463dbf8d5264a1a1c65b
|
||||||
|
|
@ -1,94 +1,144 @@
|
||||||
local wezterm = require("wezterm")
|
local wezterm = require("wezterm")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local starship_script_path = os.getenv("HOME") .. "/.local/bin/scripts/update_starship_theme.sh"
|
-- Configuration
|
||||||
local border_script_path = os.getenv("HOME") .. "/.local/bin/scripts/update_border_theme.sh"
|
local cache_dir = os.getenv("XDG_CACHE_HOME") or (os.getenv("HOME") .. "/.cache")
|
||||||
|
local cache_file = cache_dir .. "/current_theme"
|
||||||
|
|
||||||
|
-- Color scheme definitions
|
||||||
local color_schemes = {
|
local color_schemes = {
|
||||||
dark = {
|
dark = {
|
||||||
name = "Monokai (dark) (terminal.sexy)",
|
name = "Monokai (dark) (terminal.sexy)",
|
||||||
ss_palette = "monokai_pro",
|
palette = "monokai_pro",
|
||||||
tab_bar = {
|
|
||||||
active_tab = { bg_color = "#1c1f24", fg_color = "#f8f8f2" },
|
|
||||||
inactive_tab = { bg_color = "#3e4451", fg_color = "#a0a0a0" },
|
|
||||||
inactive_tab_hover = { bg_color = "#4e545e", fg_color = "#c0c0c0" },
|
|
||||||
new_tab = { bg_color = "#1c1f24", fg_color = "#f8f8f2" },
|
|
||||||
new_tab_hover = { bg_color = "#4e545e", fg_color = "#c0c0c0" },
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
light = {
|
light = {
|
||||||
name = "Solarized (light) (terminal.sexy)",
|
name = "Solarized (light) (terminal.sexy)",
|
||||||
ss_palette = "solarized_light",
|
palette = "solarized_light",
|
||||||
tab_bar = {
|
|
||||||
active_tab = { bg_color = "#eee8d5", fg_color = "#073642" },
|
|
||||||
inactive_tab = { bg_color = "#93a1a1", fg_color = "#586e75" },
|
|
||||||
inactive_tab_hover = { bg_color = "#839496", fg_color = "#586e75" },
|
|
||||||
new_tab = { bg_color = "#eee8d5", fg_color = "#073642" },
|
|
||||||
new_tab_hover = { bg_color = "#839496", fg_color = "#586e75" },
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Get the current appearance of the system or use a default value.
|
-- Cache the last known mode to minimize file reads
|
||||||
--- Falls back to "dark" if neither WezTerm GUI appearance nor environment variable is available.
|
local last_mode_cache = nil
|
||||||
--- @return string Either "dark" or "light"
|
local cache_timestamp = 0
|
||||||
local function get_appearance()
|
|
||||||
return ((wezterm.gui and wezterm.gui.get_appearance()) or os.getenv("DEFAULT_APPEARANCE") or "dark"):lower()
|
-- Fast system appearance detection (cached)
|
||||||
|
local last_appearance = nil
|
||||||
|
local appearance_timestamp = 0
|
||||||
|
local function get_system_appearance()
|
||||||
|
local now = os.time()
|
||||||
|
|
||||||
|
-- Only check system appearance every 2 seconds to reduce GUI calls
|
||||||
|
if last_appearance and (now - appearance_timestamp) < 2 then
|
||||||
|
return last_appearance
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Check if a file is executable.
|
local current_appearance = "dark" -- fallback
|
||||||
--- @param file_path string Absolute path to the file to check
|
|
||||||
--- @return boolean True if the file is executable, false otherwise
|
|
||||||
local function is_executable(file_path)
|
|
||||||
local ok = wezterm.run_child_process({ "test", "-x", file_path })
|
|
||||||
return ok == true
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Run a Starship theme updater script with the given palette.
|
if wezterm.gui then
|
||||||
--- Logs success or failure accordingly.
|
local appearance = wezterm.gui.get_appearance()
|
||||||
--- @param script_path string Absolute path to the Starship updater script
|
if appearance then
|
||||||
--- @param palette string Name of the color palette to apply
|
current_appearance = appearance:lower():find("dark") and "dark" or "light"
|
||||||
local function update_starship_theme(script_path, palette)
|
|
||||||
local script_name = script_path:match("^.+/(.+)$") or script_path
|
|
||||||
if not is_executable(script_path) then
|
|
||||||
wezterm.log_error("Script " .. script_name .. " is not executable or does not exist")
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
else
|
||||||
local ok = wezterm.run_child_process({ script_path, palette })
|
-- Fallback to environment variable (faster than GUI check)
|
||||||
if not ok then
|
local default_appearance = os.getenv("DEFAULT_APPEARANCE")
|
||||||
wezterm.log_error("Failed to run " .. script_name)
|
if default_appearance then
|
||||||
|
current_appearance = default_appearance:lower():find("dark") and "dark" or "light"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Run a Border theme updater script with the given palette.
|
last_appearance = current_appearance
|
||||||
--- @param script_path string Absolute path to the Border updater script
|
appearance_timestamp = now
|
||||||
--- @param mode string Name of the color palette to apply
|
return current_appearance
|
||||||
local function update_border_theme(script_path, mode)
|
|
||||||
local script_name = script_path:match("^.+/(.+)$") or script_path
|
|
||||||
if not is_executable(script_path) then
|
|
||||||
wezterm.log_error("Script " .. script_name .. " is not executable or does not exist")
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok = wezterm.run_child_process({ script_path, mode })
|
-- Ultra-fast cache read (non-blocking)
|
||||||
if not ok then
|
local function read_theme_cache_fast()
|
||||||
wezterm.log_error("Failed to run " .. script_name)
|
local now = os.time()
|
||||||
|
-- Only read file every 5 seconds to minimize I/O
|
||||||
|
if last_mode_cache and (now - cache_timestamp) < 5 then
|
||||||
|
return last_mode_cache
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Non-blocking file read attempt
|
||||||
|
local file = io.open(cache_file, "r")
|
||||||
|
if file then
|
||||||
|
local content = file:read("*all") -- Read entire file
|
||||||
|
file:close()
|
||||||
|
|
||||||
|
if content then
|
||||||
|
-- Strip ALL whitespace characters
|
||||||
|
content = content:gsub("%s+", "")
|
||||||
|
if content == "dark" or content == "light" then -- Simple string comparison
|
||||||
|
last_mode_cache = content
|
||||||
|
cache_timestamp = now
|
||||||
|
return content
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Apply the color scheme to the WezTerm configuration.
|
return nil
|
||||||
--- @param config table The WezTerm configuration table to modify
|
end
|
||||||
|
|
||||||
|
local function write_theme_cache_blocking(mode)
|
||||||
|
-- Ensure directory exists
|
||||||
|
os.execute(string.format('mkdir -p "%s" 2>/dev/null', cache_dir))
|
||||||
|
|
||||||
|
-- Write the cache file
|
||||||
|
local file = io.open(cache_file, "w")
|
||||||
|
if file then
|
||||||
|
file:write(mode)
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Ultra-fast async theme sync (fire-and-forget)
|
||||||
|
local function sync_theme_configs_async(mode)
|
||||||
|
local home_dir = os.getenv("HOME")
|
||||||
|
local script_path = home_dir .. "/.local/bin/scripts/update_app_theme.sh"
|
||||||
|
|
||||||
|
-- Fire-and-forget - don't even wait for command to start
|
||||||
|
local cmd = string.format('(TARGET_MODE="%s" "%s" >/dev/null 2>&1) &', mode, script_path)
|
||||||
|
print("Executing theme sync command:", cmd)
|
||||||
|
os.execute(cmd)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Apply theme configuration (with debug logging)
|
||||||
function M.apply_to_config(config)
|
function M.apply_to_config(config)
|
||||||
local mode = get_appearance():find("dark") and "dark" or "light"
|
local current_mode = get_system_appearance()
|
||||||
local theme = color_schemes[mode]
|
local cached_mode = read_theme_cache_fast()
|
||||||
|
|
||||||
|
-- Always sync if modes don't match - this ensures consistency
|
||||||
|
if current_mode ~= cached_mode then
|
||||||
|
-- Use direct file operations instead of shell commands
|
||||||
|
write_theme_cache_blocking(current_mode)
|
||||||
|
sync_theme_configs_async(current_mode)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Apply theme immediately (no I/O)
|
||||||
|
local theme = color_schemes[current_mode] or color_schemes.dark
|
||||||
config.color_scheme = theme.name
|
config.color_scheme = theme.name
|
||||||
config.colors = { tab_bar = theme.tab_bar }
|
end
|
||||||
|
|
||||||
update_starship_theme(starship_script_path, theme.ss_palette)
|
-- Fast manual mode setting
|
||||||
update_border_theme(border_script_path, mode)
|
function M.set_mode(mode)
|
||||||
|
if color_schemes[mode] then
|
||||||
|
write_theme_cache_blocking(mode)
|
||||||
|
sync_theme_configs_async(mode)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Fast mode getter
|
||||||
|
function M.get_current_mode()
|
||||||
|
return get_system_appearance()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Refresh script path cache (useful if you move the script)
|
||||||
|
function M.refresh_script_path()
|
||||||
|
local script_path_cache = nil
|
||||||
|
return script_path_cache
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ elseif wezterm.target_triple == "x86_64-apple-darwin" or wezterm.target_triple =
|
||||||
{ family = "Menlo", scale = 1.0 },
|
{ family = "Menlo", scale = 1.0 },
|
||||||
})
|
})
|
||||||
elseif wezterm.target_triple == "x86_64-unknown-linux-gnu" then
|
elseif wezterm.target_triple == "x86_64-unknown-linux-gnu" then
|
||||||
config.default_prog = { "/bin/bash", "-l" }
|
config.default_prog = { "/bin/bash" }
|
||||||
config.font = wezterm.font_with_fallback({
|
config.font = wezterm.font_with_fallback({
|
||||||
{ family = "Fira Code", scale = 1.0 },
|
{ family = "Fira Code", scale = 1.0 },
|
||||||
{ family = "MesloLGS NF", scale = 1.0 },
|
{ family = "MesloLGS NF", scale = 1.0 },
|
||||||
|
|
@ -43,6 +43,8 @@ config.front_end = "WebGpu"
|
||||||
config.term = "xterm-256color"
|
config.term = "xterm-256color"
|
||||||
config.line_height = 1.1
|
config.line_height = 1.1
|
||||||
|
|
||||||
|
config.disable_default_key_bindings = false
|
||||||
|
|
||||||
config.animation_fps = 240
|
config.animation_fps = 240
|
||||||
config.max_fps = 240
|
config.max_fps = 240
|
||||||
config.webgpu_power_preference = "HighPerformance"
|
config.webgpu_power_preference = "HighPerformance"
|
||||||
|
|
@ -496,10 +498,13 @@ local user_config = {
|
||||||
projects = {
|
projects = {
|
||||||
{ path = wezterm.home_dir .. "/.dotfiles" },
|
{ path = wezterm.home_dir .. "/.dotfiles" },
|
||||||
{ path = wezterm.home_dir .. "/Documents" },
|
{ path = wezterm.home_dir .. "/Documents" },
|
||||||
|
{ path = wezterm.home_dir .. "/Library/CloudStorage/GoogleDrive-*.com/My Drive" },
|
||||||
},
|
},
|
||||||
key = "f",
|
key = "f",
|
||||||
mods = "LEADER",
|
mods = "LEADER",
|
||||||
add_to_launch_menu = false,
|
add_to_launch_menu = false,
|
||||||
|
warmup = false,
|
||||||
|
warmup_delay_ms = 150,
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionizer.apply_to_config(config, user_config)
|
sessionizer.apply_to_config(config, user_config)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue