Skip to content

Instantly share code, notes, and snippets.

@realhackcraft
Created November 1, 2024 02:40
Show Gist options
  • Save realhackcraft/99face001b3c7984910c431f51bdbeb2 to your computer and use it in GitHub Desktop.
Save realhackcraft/99face001b3c7984910c431f51bdbeb2 to your computer and use it in GitHub Desktop.
WezTerm configs
local wezterm = require("wezterm")
local config = wezterm.config_builder()
config.front_end = "WebGpu"
-- One Dark colorscheme for background color
config.color_scheme = "OneHalfDark"
-- Font settings
config.font = wezterm.font({ family = "JetBrains Mono" })
config.font_rules = {
{
intensity = "Bold",
italic = true,
font = wezterm.font({
family = "Victor Mono",
weight = "Bold",
style = "Italic",
}),
},
{
italic = true,
intensity = "Half",
font = wezterm.font({
family = "Victor Mono",
weight = "DemiBold",
style = "Italic",
}),
},
{
italic = true,
intensity = "Normal",
font = wezterm.font({
family = "Victor Mono",
style = "Italic",
weight = "Medium",
}),
},
}
config.font_size = 15
config.underline_thickness = "1.5pt"
-- nvim doesn't put space after Nerd Font icons. This makes them large regardless.
config.allow_square_glyphs_to_overflow_width = "Always"
-- Fix font DPI issues on MacOS
config.freetype_load_flags = "NO_HINTING"
-- Window opacity
local opacity_step = 0.1
local min_opacity = 0.0
local max_opacity = 1.0
local default_opacity = 0.8
-- Define the file path for storing the opacity value
local opacity_file_path = wezterm.home_dir .. "/.config/wezterm/opacity"
local function read_opacity_from_file()
local file = io.open(opacity_file_path, "r")
if file then
local opacity = file:read("*n")
file:close()
return opacity
end
return default_opacity -- Default to max_opacity if file doesn't exist
end
local function write_opacity_to_file(opacity)
local file = io.open(opacity_file_path, "w")
if file then
file:write(string.format("%.2f\n", opacity))
file:close()
end
end
local function cycle_opacity(window)
local current_opacity = read_opacity_from_file()
local new_opacity = current_opacity - opacity_step
if new_opacity < min_opacity then
new_opacity = max_opacity
end
window:set_config_overrides({
window_background_opacity = new_opacity,
})
-- Write new opacity to the file
write_opacity_to_file(new_opacity)
end
wezterm.on("toggle-opacity", function(window, pane)
cycle_opacity(window)
end)
config.window_background_opacity = read_opacity_from_file()
config.macos_window_background_blur = 10
config.keys = {
{
key = "t",
mods = "CTRL|SHIFT|OPT|CMD",
action = wezterm.action.EmitEvent("toggle-opacity"),
},
}
-- No tab bar and window title
config.enable_tab_bar = false
config.window_decorations = "RESIZE"
-- Make right option key on Mac send alt
config.send_composed_key_when_left_alt_is_pressed = true
config.send_composed_key_when_right_alt_is_pressed = false
-- Intergration with folke/zen-mode.nvim
wezterm.on("user-var-changed", function(window, pane, name, value)
local overrides = window:get_config_overrides() or {}
if name == "ZEN_MODE" then
local incremental = value:find("+")
local number_value = tonumber(value)
if incremental ~= nil then
while number_value > 0 do
window:perform_action(wezterm.action.IncreaseFontSize, pane)
number_value = number_value - 1
end
overrides.enable_tab_bar = false
elseif number_value < 0 then
window:perform_action(wezterm.action.ResetFontSize, pane)
overrides.font_size = nil
overrides.enable_tab_bar = true
else
overrides.font_size = number_value
overrides.enable_tab_bar = false
end
end
window:set_config_overrides(overrides)
end)
return config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment