|
3 | 3 | -- https://github.com/wez/wezterm/issues/4533#issuecomment-1874094722 |
4 | 4 | -- is there a better alt? |
5 | 5 | if vim ~= nil then |
6 | | - return |
| 6 | + return |
7 | 7 | end |
8 | 8 |
|
9 | | -local wezterm = require('wezterm') |
| 9 | +local wezterm = require("wezterm") |
10 | 10 | local M = {} |
11 | 11 |
|
| 12 | +local function trim_quotes(s) |
| 13 | + return (s or ""):gsub("^['\"](.-)['\"]$", "%1") |
| 14 | +end |
| 15 | + |
12 | 16 | ---@param var string |
13 | 17 | ---@return boolean |
14 | 18 | local function is_shell_integ_user_var(var) |
15 | | - local shell_integ_user_vars = { |
16 | | - 'WEZTERM_PROG', |
17 | | - 'WEZTERM_USER', |
18 | | - 'WEZTERM_HOST', |
19 | | - 'WEZTERM_IN_TMUX', |
20 | | - } |
21 | | - for _, val in ipairs(shell_integ_user_vars) do |
22 | | - if val == var then |
23 | | - return true |
24 | | - end |
25 | | - end |
26 | | - return false |
| 19 | + local shell_integ_user_vars = { |
| 20 | + WEZTERM_PROG = true, |
| 21 | + WEZTERM_USER = true, |
| 22 | + WEZTERM_HOST = true, |
| 23 | + WEZTERM_IN_TMUX = true, |
| 24 | + } |
| 25 | + return shell_integ_user_vars[var] == true |
27 | 26 | end |
28 | 27 |
|
29 | 28 | ---Interpret the Wezterm user var that is passed in and |
@@ -52,8 +51,22 @@ function M.override_user_var(overrides, name, value) |
52 | 51 | end |
53 | 52 | overrides[name] = parsed_val |
54 | 53 | end |
55 | | - end |
56 | 54 | return overrides |
| 55 | + |
| 56 | + if name == "font" then |
| 57 | + local cleaned = trim_quotes(value) |
| 58 | + local success, font_obj = pcall(wezterm.font, cleaned) |
| 59 | + if success and font_obj then |
| 60 | + if font_obj.font and font_obj.font[1] and font_obj.font[1].family then |
| 61 | + font_obj.font[1].family = trim_quotes(font_obj.font[1].family) |
| 62 | + end |
| 63 | + overrides.font = font_obj |
| 64 | + wezterm.log_info("Applied FONT override. Cleaned value:", cleaned) |
| 65 | + else |
| 66 | + wezterm.log_error("Failed to create font object from sanitized input:", cleaned) |
| 67 | + end |
| 68 | + return overrides |
| 69 | + end |
57 | 70 | end |
58 | 71 |
|
59 | 72 | return M |
0 commit comments