From 30cbf8d1c7dab42c6e3a2def241a98524fe431a6 Mon Sep 17 00:00:00 2001 From: Jeremie Fraeys Date: Sat, 7 Feb 2026 21:03:48 -0500 Subject: [PATCH] chore: update wezterm configs and sessionizer submodule --- wezterm/.config/wezterm/plugins/sessionizer | 2 +- wezterm/.config/wezterm/theme-switcher.lua | 192 ++++++++++++-------- wezterm/.wezterm.lua | 7 +- 3 files changed, 128 insertions(+), 73 deletions(-) diff --git a/wezterm/.config/wezterm/plugins/sessionizer b/wezterm/.config/wezterm/plugins/sessionizer index c437965..1c93cd8 160000 --- a/wezterm/.config/wezterm/plugins/sessionizer +++ b/wezterm/.config/wezterm/plugins/sessionizer @@ -1 +1 @@ -Subproject commit c4379654bc179c72c57693b12d16a95d21c1651d +Subproject commit 1c93cd8c46369c40c126463dbf8d5264a1a1c65b diff --git a/wezterm/.config/wezterm/theme-switcher.lua b/wezterm/.config/wezterm/theme-switcher.lua index 70c2393..ca7206c 100644 --- a/wezterm/.config/wezterm/theme-switcher.lua +++ b/wezterm/.config/wezterm/theme-switcher.lua @@ -1,94 +1,144 @@ local wezterm = require("wezterm") - local M = {} -local starship_script_path = os.getenv("HOME") .. "/.local/bin/scripts/update_starship_theme.sh" -local border_script_path = os.getenv("HOME") .. "/.local/bin/scripts/update_border_theme.sh" +-- Configuration +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 = { - dark = { - name = "Monokai (dark) (terminal.sexy)", - ss_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 = { - name = "Solarized (light) (terminal.sexy)", - ss_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" }, - }, - }, + dark = { + name = "Monokai (dark) (terminal.sexy)", + palette = "monokai_pro", + }, + light = { + name = "Solarized (light) (terminal.sexy)", + palette = "solarized_light", + }, } ---- Get the current appearance of the system or use a default value. ---- Falls back to "dark" if neither WezTerm GUI appearance nor environment variable is available. ---- @return string Either "dark" or "light" -local function get_appearance() - return ((wezterm.gui and wezterm.gui.get_appearance()) or os.getenv("DEFAULT_APPEARANCE") or "dark"):lower() +-- Cache the last known mode to minimize file reads +local last_mode_cache = nil +local cache_timestamp = 0 + +-- 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 + + local current_appearance = "dark" -- fallback + + if wezterm.gui then + local appearance = wezterm.gui.get_appearance() + if appearance then + current_appearance = appearance:lower():find("dark") and "dark" or "light" + end + else + -- Fallback to environment variable (faster than GUI check) + local default_appearance = os.getenv("DEFAULT_APPEARANCE") + if default_appearance then + current_appearance = default_appearance:lower():find("dark") and "dark" or "light" + end + end + + last_appearance = current_appearance + appearance_timestamp = now + return current_appearance end ---- Check if a file is executable. ---- @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 +-- Ultra-fast cache read (non-blocking) +local function read_theme_cache_fast() + 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 + + return nil end ---- Run a Starship theme updater script with the given palette. ---- Logs success or failure accordingly. ---- @param script_path string Absolute path to the Starship updater script ---- @param palette string Name of the color palette to apply -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 +local function write_theme_cache_blocking(mode) + -- Ensure directory exists + os.execute(string.format('mkdir -p "%s" 2>/dev/null', cache_dir)) - local ok = wezterm.run_child_process({ script_path, palette }) - if not ok then - wezterm.log_error("Failed to run " .. script_name) - end + -- Write the cache file + local file = io.open(cache_file, "w") + if file then + file:write(mode) + file:close() + end end ---- Run a Border theme updater script with the given palette. ---- @param script_path string Absolute path to the Border updater script ---- @param mode string Name of the color palette to apply -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 +-- 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" - local ok = wezterm.run_child_process({ script_path, mode }) - if not ok then - wezterm.log_error("Failed to run " .. script_name) - end + -- 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 the color scheme to the WezTerm configuration. ---- @param config table The WezTerm configuration table to modify +-- Apply theme configuration (with debug logging) function M.apply_to_config(config) - local mode = get_appearance():find("dark") and "dark" or "light" - local theme = color_schemes[mode] + local current_mode = get_system_appearance() + local cached_mode = read_theme_cache_fast() - config.color_scheme = theme.name - config.colors = { tab_bar = theme.tab_bar } + -- 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 - update_starship_theme(starship_script_path, theme.ss_palette) - update_border_theme(border_script_path, mode) + -- Apply theme immediately (no I/O) + local theme = color_schemes[current_mode] or color_schemes.dark + config.color_scheme = theme.name +end + +-- Fast manual mode setting +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 return M diff --git a/wezterm/.wezterm.lua b/wezterm/.wezterm.lua index 4270397..e571ddb 100644 --- a/wezterm/.wezterm.lua +++ b/wezterm/.wezterm.lua @@ -28,7 +28,7 @@ elseif wezterm.target_triple == "x86_64-apple-darwin" or wezterm.target_triple = { family = "Menlo", scale = 1.0 }, }) 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({ { family = "Fira Code", scale = 1.0 }, { family = "MesloLGS NF", scale = 1.0 }, @@ -43,6 +43,8 @@ config.front_end = "WebGpu" config.term = "xterm-256color" config.line_height = 1.1 +config.disable_default_key_bindings = false + config.animation_fps = 240 config.max_fps = 240 config.webgpu_power_preference = "HighPerformance" @@ -496,10 +498,13 @@ local user_config = { projects = { { path = wezterm.home_dir .. "/.dotfiles" }, { path = wezterm.home_dir .. "/Documents" }, + { path = wezterm.home_dir .. "/Library/CloudStorage/GoogleDrive-*.com/My Drive" }, }, key = "f", mods = "LEADER", add_to_launch_menu = false, + warmup = false, + warmup_delay_ms = 150, } sessionizer.apply_to_config(config, user_config)