dotfiles/confgen.lua

126 lines
3.3 KiB
Lua
Raw Normal View History

cg.addPath "cgassets"
cg.addPath ".config"
cg.addPath ".local"
cg.addPath ".ssh"
cg.addPath ".cargo"
2023-01-21 15:14:29 +01:00
cg.addPath "etc"
2023-06-06 13:24:07 +02:00
cg.addFile ".gtkrc-2.0.cgt"
2023-04-26 11:06:56 +02:00
cg.addFile ".Xresources.cgt"
2023-05-13 18:51:31 +02:00
cg.addFile ".replrc"
2023-06-06 13:24:07 +02:00
cg.addFile ".vieterrc.cgt"
2023-04-26 11:06:56 +02:00
2023-08-29 08:25:15 +02:00
cg.onDone(function(errors)
if errors then
print "ERRORS DURING CONFGEN"
else
print "updating gsettings"
cg.opt.system("gsettings set org.gnome.desktop.interface icon-theme " .. cg.opt.icon_theme)
cg.opt.system("gsettings set org.gnome.desktop.interface gtk-theme " .. cg.opt.gtk_theme)
cg.opt.system("gsettings set org.gnome.desktop.interface cursor-theme " .. cg.opt.cursor.theme)
cg.opt.system("gsettings set org.gnome.desktop.interface cursor-size " .. cg.opt.cursor.size)
cg.opt.system('gsettings set org.gnome.desktop.interface font-name "' .. cg.opt.font .. ' 11"')
2023-08-29 08:25:15 +02:00
end
end)
local nix = (loadfile "nix/cgnix/nix.lua" or function()
print "no cgnix file!"
return {}
end)()
2024-04-05 22:56:00 +02:00
cg.opt.nix = nix
2024-04-26 17:31:39 +02:00
local fennel = (loadfile(nix["fennel.lua"] or "/usr/share/lua/5.4/fennel.lua")())
2023-09-02 14:02:00 +02:00
2023-04-26 10:12:40 +02:00
-- Recursively merge 2 tables
local function merge(a, b)
2023-08-27 21:05:25 +02:00
if b[1] then -- b is a list
return b
end
2023-04-26 10:12:40 +02:00
for k, v in pairs(b) do
if type(v) == "table" and type(a[k]) == "table" then
2023-08-27 21:05:25 +02:00
a[k] = merge(a[k], v)
2023-04-26 10:12:40 +02:00
else
a[k] = v
end
end
return a
end
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")
2023-06-09 14:28:26 +02:00
if not file then
2023-01-21 00:01:23 +01:00
return ""
end
return file:read "*a"
end
2023-01-21 15:14:29 +01:00
2023-06-09 14:28:26 +02:00
-- Returns the contents of a file
cg.opt.read = function(fname)
local file = io.open(fname, "r")
if not file then
return nil
end
2023-04-26 10:12:40 +02:00
2023-06-09 14:28:26 +02:00
return file:read "*a"
2023-04-26 10:12:40 +02:00
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
local data, _ = handle:read("*a"):gsub("%s$", "")
return data
2023-01-21 15:14:29 +01:00
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.
2023-09-02 14:02:00 +02:00
cg.opt.fennelCompile = fennel.compileString
2023-02-19 14:44:15 +01:00
2023-09-02 14:02:00 +02:00
-- Evaluate fennel code and JSONify the result. Meant to be used as a post-processor.
cg.opt.fennelToJSON = function(str)
return cg.toJSON(fennel.eval(str))
2023-02-19 14:44:15 +01:00
end
2023-04-29 00:13:00 +02:00
-- Check if the given file exists
cg.opt.fileExists = function(path)
local f = io.open(path, "r")
if f then
f:close()
return true
end
return false
end
2024-03-08 13:04:40 +01:00
-- Set the currently active wayland compositor. Updates options for templates as well as gsettings.
cg.opt.setCurrentWaylandCompositor = function(comp)
cg.opt.wayland_compositor = comp
if comp == "river" then
cg.opt.system 'gsettings set org.gnome.desktop.wm.preferences button-layout ""'
else
cg.opt.system "gsettings reset org.gnome.desktop.wm.preferences button-layout"
end
end
cg.opt = merge(cg.opt, require "cg_opts")
local local_opts = loadfile(os.getenv "HOME" .. "/.config/mzte_localconf/opts.lua")
if local_opts then
cg.opt = merge(cg.opt, local_opts())
end