Files
Hyprdots/lua/lib/systemd.lua
T
2026-06-12 17:12:25 -04:00

32 lines
839 B
Lua

local utils = require("lua.lib.utils")
local M = {}
function M.is_user_unit_exists(unit)
return utils.command_success("systemctl --user cat " .. utils.shell_quote(unit) .. " >/dev/null 2>&1")
end
M.user_unit_dir = CONFIG_HOME .. "/systemd/user"
function M.ensure_user_unit(unit, source)
if M.is_user_unit_exists(unit) then
return true
end
local target_dir = M.user_unit_dir
local target = target_dir .. "/" .. unit
local cmd = table.concat({
"mkdir -p " .. utils.shell_quote(target_dir),
"ln -s " .. utils.shell_quote(source) .. " " .. utils.shell_quote(target),
"systemctl --user daemon-reload",
}, " && ")
return utils.command_success(cmd)
end
function M.start_user_unit(unit)
return utils.command_success("systemctl --user start " .. utils.shell_quote(unit) .. " >/dev/null 2>&1")
end
return M