repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
wezterm/bugabinga/exec_domains.lua
RawFile outline
local wez = require 'wezterm'
local function append_all(dst, src)
for _, value in ipairs(src) do
table.insert(dst, value)
end
end
local function scoped_domain(name, label, properties)
return wez.exec_domain(name, function(cmd)
local args = cmd.args or { 'nu', '--login' }
local env = cmd.set_environment_variables or {}
env.WEZTERM_EXEC_DOMAIN = name
cmd.set_environment_variables = env
local unit = 'wezterm-' .. name:gsub('[^%w_.-]', '-') .. '-' .. tostring(env.WEZTERM_PANE or os.time())
local wrapped = {
'systemd-run',
'--user',
'--scope',
'--same-dir',
'--collect',
'--quiet',
'--unit=' .. unit,
'--description=WezTerm ' .. name,
}
for _, property in ipairs(properties) do
table.insert(wrapped, '-p')
table.insert(wrapped, property)
end
append_all(wrapped, args)
cmd.args = wrapped
return cmd
end, label)
end
return function(cfg)
if not wez.target_triple:find( 'linux', 1, true ) then return end
cfg.exec_domains = {
scoped_domain('scope:build', 'scope:build CPU 25% MEM max 256M', {
'CPUQuota=25%',
'MemoryMax=256M',
'MemorySwapMax=0',
'OOMPolicy=stop',
}),
}
end