From 8bdab399c241805b2758221634fcb9c170a8e79d Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sun, 28 May 2023 14:58:22 +0200 Subject: [PATCH] set XDG env vars --- scripts/mzteinit/src/env.zig | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/mzteinit/src/env.zig b/scripts/mzteinit/src/env.zig index 24ec833..c070270 100644 --- a/scripts/mzteinit/src/env.zig +++ b/scripts/mzteinit/src/env.zig @@ -8,6 +8,8 @@ const DelimitedBuilder = @import("DelimitedBuilder.zig"); /// Initialize the environment. /// Returns true if the environment should be transferred to the system daemon. pub fn populateEnvironment(env: *std.process.EnvMap) !bool { + var buf: [512]u8 = undefined; + if (env.get("MZTE_ENV_SET")) |_| { return false; } @@ -21,6 +23,16 @@ pub fn populateEnvironment(env: *std.process.EnvMap) !bool { try env.put("MZTE_ENV_SET", "1"); + // XDG vars + inline for (.{ + .{ "XDG_DATA_HOME", ".local/share" }, + .{ "XDG_CONFIG_HOME", ".config" }, + .{ "XDG_STATE_HOME", ".local/state" }, + .{ "XDG_CACHE_HOME", ".local/cache" }, + }) |kv| { + try env.put(kv.@"0", try std.fmt.bufPrint(&buf, "{s}/{s}", .{ home, kv.@"1" })); + } + // set shell to fish to prevent anything from defaulting to mzteinit try env.put("SHELL", "/usr/bin/fish"); @@ -39,8 +51,6 @@ pub fn populateEnvironment(env: *std.process.EnvMap) !bool { var b = DelimitedBuilder.init(alloc, ':'); errdefer b.deinit(); - var buf: [512]u8 = undefined; - const fixed_home = [_][]const u8{ ".mix/escripts", ".cargo/bin", @@ -84,8 +94,6 @@ pub fn populateEnvironment(env: *std.process.EnvMap) !bool { var b = DelimitedBuilder.init(alloc, ';'); errdefer b.deinit(); - var buf: [512]u8 = undefined; - const fixed_home = [_][]const u8{ ".local/lib/lua/?.so", ".local/lib/lua/?.lua",