-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfgen.lua
More file actions
150 lines (121 loc) · 4.27 KB
/
confgen.lua
File metadata and controls
150 lines (121 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
cg.addPath "cgassets"
cg.addPath ".cargo"
cg.addPath ".config"
cg.addPath ".julia"
cg.addPath ".librewolf"
cg.addPath ".local"
cg.addPath ".ssh"
cg.addPath "etc"
cg.addFile ".Xresources.cgt"
cg.addFile ".bashrc"
cg.addFile ".clang-format.cgt"
cg.addFile ".ghci"
cg.addFile ".gtkrc-2.0.cgt"
cg.addFile ".inputrc"
cg.addFile ".screenrc"
cg.addFile ".stylua.toml.cgt"
cg.addFile "hxformat.json.cgt"
cg.onDone(function(errors)
if errors then
print "ERRORS DURING CONFGEN"
else
print "updating dconf"
cg.opt.system "dconf load / <~/confgenfs/cgassets/dconf.ini"
end
end)
if cg.fs then
-- Cache files in ConfgenFS for 5 seconds by default
cg.fs.cachetime = 5 * 1000
end
local nix = (loadfile "nix/cgnix/nix.lua" or function()
print "no cgnix file!"
return {}
end)()
cg.opt.nix = nix
local fennel = (loadfile(nix["fennel.lua"] or "/usr/share/lua/5.4/fennel.lua")())
cg.opt.getDeviceConfPath = function(id)
return os.getenv "HOME" .. "/.config/mzte_localconf/" .. id
end
-- This function is called in templates to allow adding device-specific configs.
cg.opt.getDeviceConf = function(id)
local path = cg.opt.getDeviceConfPath(id)
local file = io.open(path, "r")
if not file then return "" end
return file:read "*a"
end
cg.opt.getLuaDeviceConf = function(id)
local chunk = loadfile(cg.opt.getDeviceConfPath(id .. ".lua"))
if not chunk then return nil end
return chunk()
end
-- Returns the contents of a file
cg.opt.read = function(fname)
local file = io.open(fname, "r")
if not file then return nil end
return file:read "*a"
end
-- 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$", "")
handle:close()
return data
end
-- 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
-- Compile the input as fennel. Meant to be used as a post-processor.
cg.opt.fennelCompile = fennel.compileString
-- Evaluate fennel code and JSONify the result. Meant to be used as a post-processor.
cg.opt.fennelToJSON = function(str) return cg.fmt.json.serialize(fennel.eval(str)) end
-- 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
-- Check if a TERM environment variable describes a terminal supporting the kitty image protocol.
cg.opt.termSupportsKittyImages = function(term)
if not term then return false end
return term:match "kitty" or term:match "ghostty"
end
-- Returns true iff the given terminal command line (usually the return value of fsctx:getCallerCmd)
-- should cause a terminal to be launched with a larger font size.
cg.opt.shouldUseLargeFontForCmdline = function(cmdline)
return cg.lib.contains(cmdline, function(arg)
return arg:match "iamb$"
end)
end
-- 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" or comp == "river-classic" 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
-- This will set a "safe mode" flag which prevents supported messenger apps from showing images.
-- Useful for opening matrix in public spaces due to recent spam.
cg.opt.toggleSafeMode = function()
cg.opt.safe_mode = not cg.opt.safe_mode
if cg.opt.safe_mode then
cg.opt.system [[notify-send -a "MZTE System" "Safe mode enabled"]]
else
cg.opt.system [[notify-send -a "MZTE System" "Safe mode disabled"]]
end
end
-- Essentially undoes all cached "require" calls. This is useful for iterating on code running in
-- ConfgenFS to reload.
cg.opt.unloadModules = function()
for k, _ in pairs(package.loaded) do
package.loaded[k] = nil
end
end
require "cg_opts"
require "cg_lazies"
local local_opts = loadfile(os.getenv "HOME" .. "/.config/mzte_localconf/opts.lua")
if local_opts then local_opts() end