splits out configuration into central modules

This commit is contained in:
Dennis Schoepf 2025-05-29 18:26:46 +02:00
parent 58ffb417dd
commit b44654b9a2
63 changed files with 20 additions and 20 deletions

View file

@ -0,0 +1,32 @@
local wezterm = require("wezterm")
local theme = wezterm.plugin.require("https://github.com/neapsix/wezterm").main
local helpers = require("helpers")
local M = {}
local scheme = wezterm.get_builtin_color_schemes()["rose-pine"]
scheme.selection_fg = "white"
scheme.selection_bg = "teal"
scheme.copy_mode_active_highlight_bg = { AnsiColor = "Teal" }
scheme.copy_mode_active_highlight_fg = { AnsiColor = "White" }
scheme.copy_mode_inactive_highlight_bg = { AnsiColor = "Silver" }
scheme.copy_mode_inactive_highlight_fg = { AnsiColor = "Black" }
function M.apply_to_config(config)
config.color_schemes = {
["rose-pine"] = scheme,
}
config.color_scheme = "rose-pine"
config.font = wezterm.font("VictorMono Nerd Font", { weight = "DemiBold", stretch = "Normal", style = "Normal" })
config.font_size = 18.5
config.window_decorations = "RESIZE"
config.window_padding = helpers.get_padding(20, 15)
config.window_background_opacity = 0.97
config.macos_window_background_blur = 30
config.command_palette_font_size = 19
config.command_palette_fg_color = theme.colors().foreground
config.command_palette_bg_color = theme.colors().tab_bar.active_tab.bg_color
end
return M

View file

@ -0,0 +1,55 @@
local wezterm = require("wezterm")
local M = {}
function M.project_dir()
return wezterm.home_dir .. "/dev"
end
function M.project_dirs()
local projects = { wezterm.home_dir }
for _, dir in ipairs(wezterm.glob(M.project_dir() .. "/*")) do
table.insert(projects, dir)
end
return projects
end
function M.get_outdated_packages()
local success, stdout, stderr =
wezterm.run_child_process({ "sh", "-c", "/opt/homebrew/bin/brew outdated -q | wc -l" })
if success ~= true then
wezterm.log_error(stderr)
return "X"
end
return stdout:gsub("%s+", "")
end
function M.get_primary_battery_state()
local battery_info = wezterm.battery_info()
return string.format("%.0f%%", battery_info[1].state_of_charge * 100)
end
function M.get_padding(padding, remove_padding_bottom)
return {
left = padding,
right = padding,
top = padding,
bottom = padding - remove_padding_bottom,
}
end
function M.move_pane(key, direction)
return {
key = key,
mods = "LEADER",
action = wezterm.action.ActivatePaneDirection(direction),
}
end
return M

View file

@ -0,0 +1,88 @@
local wezterm = require("wezterm")
local helpers = require("helpers")
local projects = require("projects")
local M = {}
function M.apply_to_config(config)
config.leader = { key = "b", mods = "CTRL", timeout_milliseconds = 1000 }
config.keys = {
-- Window/Pane Management
{
key = "|",
mods = "LEADER",
action = wezterm.action.SplitHorizontal({ domain = "CurrentPaneDomain" }),
},
{
key = "-",
mods = "LEADER",
action = wezterm.action.SplitVertical({ domain = "CurrentPaneDomain" }),
},
{
key = "-",
mods = "LEADER",
action = wezterm.action.SplitVertical({ domain = "CurrentPaneDomain" }),
},
{
key = "x",
mods = "LEADER",
action = wezterm.action.CloseCurrentPane({ confirm = true }),
},
{
mods = "LEADER",
key = "z",
action = wezterm.action.TogglePaneZoomState,
},
{
mods = "LEADER",
key = "u",
action = wezterm.action.PaneSelect({
mode = "SwapWithActive",
}),
},
-- Navigation
helpers.move_pane("j", "Down"),
helpers.move_pane("k", "Up"),
helpers.move_pane("h", "Left"),
helpers.move_pane("l", "Right"),
-- Workspaces
{
key = "s",
mods = "LEADER",
action = projects.choose(),
},
{
key = "w",
mods = "LEADER",
-- Present a list of existing workspaces
action = wezterm.action.ShowLauncherArgs({ flags = "FUZZY|WORKSPACES" }),
},
-- Misc
{
key = " ",
mods = "LEADER",
action = wezterm.action.ActivateCommandPalette,
},
{
key = "[",
mods = "LEADER",
action = wezterm.action.ActivateCopyMode,
},
{
key = "c",
mods = "LEADER",
action = wezterm.action.SpawnTab("CurrentPaneDomain"),
},
}
for i = 1, 8 do
table.insert(config.keys, {
key = tostring(i),
mods = "LEADER",
action = wezterm.action.ActivateTab(i - 1),
})
end
end
return M

View file

@ -0,0 +1,22 @@
local wezterm = require("wezterm")
local hn = wezterm.hostname()
local helpers = require("helpers")
local M = {}
function M.apply_to_config(config)
if hn == "dnsc-work" then
config.window_background_opacity = 0.975
config.font_size = 19
end
if hn == "dnsc-desktop" then
config.font = wezterm.font("Victor Mono", { weight = "DemiBold" })
config.font_size = 14
config.window_decorations = "RESIZE"
config.window_padding = helpers.get_padding(18, 6)
config.window_background_opacity = 1
end
end
return M

View file

@ -0,0 +1,33 @@
local wezterm = require("wezterm")
local helpers = require("helpers")
local M = {}
function M.choose()
local choices = {}
for _, value in ipairs(helpers.project_dirs()) do
table.insert(choices, { label = value })
end
return wezterm.action.InputSelector({
title = "Projects",
choices = choices,
fuzzy = true,
action = wezterm.action_callback(function(child_window, child_pane, _, label)
if not label then
return
end
child_window:perform_action(
wezterm.action.SwitchToWorkspace({
name = label:match("([^/]+)$"),
spawn = { cwd = label },
}),
child_pane
)
end),
})
end
return M

View file

@ -0,0 +1,28 @@
local wezterm = require("wezterm")
local mux = wezterm.mux
local helpers = require("helpers")
local M = {}
wezterm.on("gui-startup", function(cmd)
local args = {}
if cmd then
args = cmd.args
end
-- WORKSPACES
-- W: dennis
local _, _, _ = mux.spawn_window({
workspace = "dennis",
cwd = wezterm.home_dir,
args = args,
})
mux.set_active_workspace("dennis")
end)
function M.apply_to_config(config)
return config
end
return M

View file

@ -0,0 +1,40 @@
local wezterm = require("wezterm")
local theme = wezterm.plugin.require("https://github.com/neapsix/wezterm").main
local helpers = require("helpers")
local M = {}
local function get_elements(for_window)
return {
{ Background = { Color = theme.colors().tab_bar.background } },
{ Foreground = { Color = theme.colors().tab_bar.inactive_tab.fg_color } },
{ Text = "h:" .. wezterm.hostname() .. " " },
{ Text = "upgrades:" .. helpers.get_outdated_packages() .. " " },
{ Text = "bat:" .. helpers.get_primary_battery_state() .. " " },
{ Background = { Color = theme.colors().tab_bar.active_tab.bg_color } },
{ Foreground = { Color = theme.colors().tab_bar.active_tab.fg_color } },
{ Text = " session >> " .. for_window:active_workspace() .. " " },
}
end
wezterm.on("update-right-status", function(window, _)
window:set_right_status(wezterm.format(get_elements(window)))
end)
function M.apply_to_config(config)
config.enable_tab_bar = true
config.use_fancy_tab_bar = true
config.tab_bar_at_bottom = false
config.window_frame = {
inactive_titlebar_bg = theme.colors().tab_bar.background,
active_titlebar_bg = theme.colors().tab_bar.background,
font = wezterm.font({ family = "Victor Mono", weight = "Bold" }),
}
config.colors = {
tab_bar = theme.colors().tab_bar,
}
end
return M

View file

@ -0,0 +1,21 @@
local wezterm = require("wezterm")
local appearance = require("appearance")
local tab_bar = require("tab_bar")
local startup = require("startup")
local keybindings = require("keybindings")
local overrides = require("overrides")
local config = {}
if wezterm.config_builder then
---@diagnostic disable-next-line: lowercase-global
config = wezterm.config_builder()
end
appearance.apply_to_config(config)
tab_bar.apply_to_config(config)
startup.apply_to_config(config)
keybindings.apply_to_config(config)
overrides.apply_to_config(config)
return config