2023-01-20 22:30:45 +01:00
|
|
|
cg.addPath ".config"
|
|
|
|
cg.addPath ".local"
|
|
|
|
cg.addPath ".ssh"
|
|
|
|
cg.addPath ".cargo"
|
2023-01-21 15:14:29 +01:00
|
|
|
cg.addPath "etc"
|
2023-01-20 22:30:45 +01:00
|
|
|
|
2023-04-26 11:06:56 +02:00
|
|
|
cg.addFile ".Xresources.cgt"
|
|
|
|
|
2023-04-26 10:12:40 +02:00
|
|
|
-- Recursively merge 2 tables
|
|
|
|
local function merge(a, b)
|
|
|
|
for k, v in pairs(b) do
|
|
|
|
if type(v) == "table" and type(a[k]) == "table" then
|
|
|
|
merge(a[k], v)
|
|
|
|
else
|
|
|
|
a[k] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return a
|
2023-01-20 22:30:45 +01:00
|
|
|
end
|
2023-01-21 00:01:23 +01:00
|
|
|
|
2023-04-26 10:12:40 +02:00
|
|
|
cg.opt = merge(cg.opt, require "cg_opts")
|
|
|
|
|
2023-01-21 00:01:23 +01:00
|
|
|
-- This function is called in templates to allow adding device-specific configs.
|
|
|
|
cg.opt.getDeviceConf = function(id)
|
|
|
|
local path = os.getenv "HOME" .. "/.config/mzte_localconf/" .. id
|
|
|
|
local file = io.open(path, "r")
|
|
|
|
|
|
|
|
if file == nil then
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
|
|
|
|
return file:read "*a"
|
|
|
|
end
|
2023-01-21 15:14:29 +01:00
|
|
|
|
2023-04-26 10:12:40 +02:00
|
|
|
local local_opts = loadfile(os.getenv "HOME" .. "/.config/mzte_localconf/opts.lua")
|
|
|
|
|
|
|
|
if local_opts then
|
|
|
|
cg.opt = merge(cg.opt, local_opts())
|
|
|
|
end
|
|
|
|
|
2023-01-21 15:14:29 +01:00
|
|
|
-- Get the output of a system command
|
|
|
|
cg.opt.system = function(cmd)
|
|
|
|
local handle = io.popen(cmd)
|
|
|
|
if handle == nil then
|
|
|
|
error("Failed to spawn process" .. cmd)
|
|
|
|
end
|
|
|
|
return handle:read("*a"):gsub("%s+", "")
|
|
|
|
end
|
2023-01-24 17:38:02 +01:00
|
|
|
|
|
|
|
-- Compile the input as lua. Meant to be used as a post-processor.
|
|
|
|
cg.opt.luaCompile = function(lua)
|
|
|
|
return string.dump(loadstring(lua), true)
|
|
|
|
end
|
2023-02-19 14:44:15 +01:00
|
|
|
|
|
|
|
-- Compile the input as fennel. Meant to be used as a post-processor.
|
|
|
|
cg.opt.fennelCompile = function(fnl)
|
|
|
|
local handle = io.popen("fennel -c - > /tmp/cgfnl", "w")
|
|
|
|
if handle == nil then
|
|
|
|
error "Failed to spawn fennel"
|
|
|
|
end
|
|
|
|
|
|
|
|
handle:write(fnl)
|
|
|
|
handle:close()
|
|
|
|
|
|
|
|
local f = io.open "/tmp/cgfnl"
|
|
|
|
local res = f:read "*a"
|
|
|
|
f:close()
|
|
|
|
return res
|
|
|
|
end
|