mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-14 00:13:48 +01:00
support local confgen options
This commit is contained in:
parent
ca3b276b38
commit
2d073e4a66
1 changed files with 18 additions and 2 deletions
20
confgen.lua
20
confgen.lua
|
@ -4,10 +4,20 @@ cg.addPath ".ssh"
|
|||
cg.addPath ".cargo"
|
||||
cg.addPath "etc"
|
||||
|
||||
for k, v in pairs(require "cg_opts") do
|
||||
cg.opt[k] = v
|
||||
-- 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
|
||||
end
|
||||
|
||||
cg.opt = merge(cg.opt, require "cg_opts")
|
||||
|
||||
-- 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
|
||||
|
@ -20,6 +30,12 @@ cg.opt.getDeviceConf = function(id)
|
|||
return file:read "*a"
|
||||
end
|
||||
|
||||
local local_opts = loadfile(os.getenv "HOME" .. "/.config/mzte_localconf/opts.lua")
|
||||
|
||||
if local_opts then
|
||||
cg.opt = merge(cg.opt, local_opts())
|
||||
end
|
||||
|
||||
-- Get the output of a system command
|
||||
cg.opt.system = function(cmd)
|
||||
local handle = io.popen(cmd)
|
||||
|
|
Loading…
Reference in a new issue