From 7a839ebd04c6cefad9b0939899799069638b5429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20B=C3=B8e?= Date: Sat, 24 May 2025 02:13:47 +0200 Subject: [PATCH] Added font support Needs testing before merge --- plugin/init.lua | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/plugin/init.lua b/plugin/init.lua index 55c6d4a..2ee1125 100644 --- a/plugin/init.lua +++ b/plugin/init.lua @@ -3,27 +3,26 @@ -- https://github.com/wez/wezterm/issues/4533#issuecomment-1874094722 -- is there a better alt? if vim ~= nil then - return + return end -local wezterm = require('wezterm') +local wezterm = require("wezterm") local M = {} +local function trim_quotes(s) + return (s or ""):gsub("^['\"](.-)['\"]$", "%1") +end + ---@param var string ---@return boolean local function is_shell_integ_user_var(var) - local shell_integ_user_vars = { - 'WEZTERM_PROG', - 'WEZTERM_USER', - 'WEZTERM_HOST', - 'WEZTERM_IN_TMUX', - } - for _, val in ipairs(shell_integ_user_vars) do - if val == var then - return true - end - end - return false + local shell_integ_user_vars = { + WEZTERM_PROG = true, + WEZTERM_USER = true, + WEZTERM_HOST = true, + WEZTERM_IN_TMUX = true, + } + return shell_integ_user_vars[var] == true end ---Interpret the Wezterm user var that is passed in and @@ -52,8 +51,22 @@ function M.override_user_var(overrides, name, value) end overrides[name] = parsed_val end - end return overrides + + if name == "font" then + local cleaned = trim_quotes(value) + local success, font_obj = pcall(wezterm.font, cleaned) + if success and font_obj then + if font_obj.font and font_obj.font[1] and font_obj.font[1].family then + font_obj.font[1].family = trim_quotes(font_obj.font[1].family) + end + overrides.font = font_obj + wezterm.log_info("Applied FONT override. Cleaned value:", cleaned) + else + wezterm.log_error("Failed to create font object from sanitized input:", cleaned) + end + return overrides + end end return M