mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-07 19:49:53 -05:00
turns out passing in the -u flag didn't actually work before...
Additionally, in the case that the directory doesn't exist mezzaluna will default back to the config at ~/.config/mez/
This commit is contained in:
parent
fd997e8219
commit
f60a2c5c37
3 changed files with 34 additions and 46 deletions
|
|
@ -1,13 +1,3 @@
|
|||
local env_conf = os.getenv("XDG_CONFIG_HOME")
|
||||
|
||||
if not env_conf then
|
||||
env_conf = os.getenv("HOME")
|
||||
if not env_conf then
|
||||
error("Couldn't determine potential config directory is $HOME set?")
|
||||
end
|
||||
env_conf = mez.fs.joinpath(env_conf, ".config")
|
||||
end
|
||||
|
||||
-- allow loading files in the runtime directory
|
||||
package.path = package.path..";"..mez.fs.joinpath(mez.path.runtime, "?.lua")
|
||||
mez.inspect = require("inspect").inspect
|
||||
|
|
@ -15,6 +5,18 @@ mez.inspect = require("inspect").inspect
|
|||
mez.path.base_config = mez.fs.joinpath(mez.path.runtime, "master.lua")
|
||||
|
||||
if not mez.path.config then
|
||||
mez.path.config = mez.fs.joinpath(env_conf, "mez", "init.lua")
|
||||
package.path = package.path..";"..mez.fs.joinpath(env_conf, "mez", "lua", "?.lua")
|
||||
local env_conf = os.getenv("XDG_CONFIG_HOME")
|
||||
|
||||
if not env_conf then
|
||||
env_conf = os.getenv("HOME")
|
||||
if not env_conf then
|
||||
error("Couldn't determine potential config directory is $HOME set?")
|
||||
end
|
||||
env_conf = mez.fs.joinpath(env_conf, ".config")
|
||||
end
|
||||
|
||||
mez.path.config = mez.fs.joinpath(env_conf, "mez")
|
||||
end
|
||||
|
||||
package.path = package.path..";"..mez.fs.joinpath(mez.path.config, "lua", "?.lua")
|
||||
mez.path.config = mez.fs.joinpath(mez.path.config, "init.lua")
|
||||
|
|
|
|||
|
|
@ -48,33 +48,12 @@ pub fn loadRuntimeDir(self: *zlua.Lua) !void {
|
|||
}
|
||||
|
||||
pub fn setBaseConfig(self: *zlua.Lua, path: []const u8) !void {
|
||||
{
|
||||
_ = try self.getGlobal("mez");
|
||||
defer self.pop(1);
|
||||
_ = self.getField(-1, "path");
|
||||
defer self.pop(1);
|
||||
const new_path = try std.fs.path.join(gpa, &[_][]const u8{ path, "init.lua" });
|
||||
defer gpa.free(new_path);
|
||||
_ = self.pushString(new_path);
|
||||
_ = self.pushString(path);
|
||||
self.setField(-2, "config");
|
||||
}
|
||||
{
|
||||
_ = try self.getGlobal("mez");
|
||||
defer self.pop(1);
|
||||
_ = self.getField(-1, "path");
|
||||
defer self.pop(1);
|
||||
const cur_path = self.toString(-1) catch "";
|
||||
|
||||
const unsentinel: []const u8 = std.mem.span(cur_path.ptr);
|
||||
const new_path = try std.mem.concat(gpa, u8, &[_][]const u8{
|
||||
unsentinel,
|
||||
";",
|
||||
path,
|
||||
});
|
||||
defer gpa.free(new_path);
|
||||
_ = self.pushString(new_path);
|
||||
_ = self.setField(-2, "path");
|
||||
}
|
||||
}
|
||||
|
||||
fn loadBaseConfig(self: *zlua.Lua) !void {
|
||||
|
|
@ -160,7 +139,12 @@ pub fn init(self: *Lua, cfg: Config) !void {
|
|||
|
||||
openMezLibs(self.state);
|
||||
|
||||
if (!cfg.enabled) try setBaseConfig(self.state, "");
|
||||
if (!cfg.enabled) {
|
||||
try setBaseConfig(self.state, "");
|
||||
} else if (cfg.path) |path| {
|
||||
defer gpa.free(path);
|
||||
try setBaseConfig(self.state, path);
|
||||
}
|
||||
loadRuntimeDir(self.state) catch |err| if (err == error.LuaRuntime) {
|
||||
std.log.warn("{s}", .{try self.state.toString(-1)});
|
||||
};
|
||||
|
|
@ -169,10 +153,6 @@ pub fn init(self: *Lua, cfg: Config) !void {
|
|||
std.log.warn("{s}", .{try self.state.toString(-1)});
|
||||
};
|
||||
|
||||
if (cfg.path) |path| {
|
||||
defer gpa.free(path);
|
||||
try setBaseConfig(self.state, path);
|
||||
}
|
||||
if (cfg.enabled) {
|
||||
loadConfigDir(self.state) catch |err| if (err == error.LuaRuntime) {
|
||||
std.log.warn("{s}", .{try self.state.toString(-1)});
|
||||
|
|
|
|||
10
src/main.zig
10
src/main.zig
|
|
@ -54,9 +54,15 @@ pub fn main() !void {
|
|||
var lua_config: Lua.Config = .{ .enabled = true, .path = null };
|
||||
if (res.args.u != null and res.args.clean == 1) {
|
||||
std.debug.panic("You cannot set both -u and --clean", .{});
|
||||
} else if (res.args.u != null) {
|
||||
} else if (res.args.u != null) blk: {
|
||||
// this is freed in lua/lua.zig
|
||||
const path = try std.fs.cwd().realpathAlloc(gpa, res.args.u.?);
|
||||
const path = std.fs.cwd().realpathAlloc(gpa, res.args.u.?) catch |err| switch (err) {
|
||||
error.FileNotFound => {
|
||||
std.log.err("Path {s} does not exist, and therefore won't be used for the configuration.", .{ res.args.u.? });
|
||||
break :blk;
|
||||
},
|
||||
else => return err,
|
||||
};
|
||||
lua_config.path = path;
|
||||
} else if (res.args.clean == 1) {
|
||||
lua_config.enabled = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue