Added user XDG variables

This commit is contained in:
Salvo 2025-12-24 19:46:04 +01:00
commit d12f29015c

View file

@ -198,6 +198,21 @@ fn initEnv(allocator: std.mem.Allocator, entry: interop.UsernameEntry, path_env:
if (entry.home) |home| {
try interop.setEnvironmentVariable(allocator, "HOME", home, true);
try interop.setEnvironmentVariable(allocator, "PWD", home, true);
// set XDG env as per https://wiki.archlinux.org/title/XDG_Base_Directory
const n = comptime 4;
const xdgVars: [n][]const u8 = .{
"XDG_CONFIG_HOME",
"XDG_CACHE_HOME",
"XDG_DATA_HOME",
"XDG_STATE_HOME",
};
const xdgPaths: [n][]const u8 = .{".config", ".cache", ".local/share", ".local/state"};
for (0..n) |i| {
const value = try std.fmt.allocPrint(allocator, "{s}/{s}", .{ home, xdgPaths[i] });
defer allocator.free(value);
try interop.setEnvironmentVariable(allocator, xdgVars[i], value, false);
}
} else return error.NoHomeDirectory;
try interop.setEnvironmentVariable(allocator, "SHELL", entry.shell.?, true);