diff --git a/scripts/mzteinit/src/env.zig b/scripts/mzteinit/src/env.zig index 1143ddf..6bf9628 100644 --- a/scripts/mzteinit/src/env.zig +++ b/scripts/mzteinit/src/env.zig @@ -29,6 +29,50 @@ pub fn populateEnvironment(env: *std.process.EnvMap) !bool { }; defer alloc.free(home); + // PATH + { + var bufstream = std.io.fixedBufferStream(&buf); + var b = delimitedWriter(bufstream.writer(), ':'); + + for ([_][]const u8{ + ".nix-profile/bin", + ".mix/escripts", + ".cargo/bin", + ".local/bin", + "go/bin", + ".roswell/bin", + }) |fixed| { + try b.push(try std.fmt.bufPrint(&sbuf, "{s}/{s}", .{ home, fixed })); + } + + // racket bins + racket: { + try msg("acquiring racket binary path...", .{}); + const res = std.process.Child.run(.{ + .allocator = alloc, + .argv = &.{ + "racket", + "-l", + "racket/base", + "-e", + "(require setup/dirs) (display (path->string (find-user-console-bin-dir)))", + }, + }) catch break :racket; + defer alloc.free(res.stdout); + defer alloc.free(res.stderr); + + try b.push(res.stdout); + + log.info("racket binary path registered", .{}); + } + + if (env.get("PATH")) |system_path| { + try b.push(system_path); + } + + try env.put("PATH", bufstream.getWritten()); + } + try env.put("MZTE_ENV_SET", "1"); // XDG vars @@ -42,9 +86,13 @@ pub fn populateEnvironment(env: *std.process.EnvMap) !bool { } // set shell to nu to prevent anything from defaulting to mzteinit - if (try util.findInPath(alloc, "nu")) |fish| { - defer alloc.free(fish); - try env.put("SHELL", fish); + if (try util.findInPath( + alloc, + env.get("PATH") orelse unreachable, + "nu", + )) |nu| { + defer alloc.free(nu); + try env.put("SHELL", nu); } else { log.warn("nu not found! setting $SHELL to /bin/sh", .{}); try env.put("SHELL", "/bin/sh"); @@ -134,50 +182,6 @@ pub fn populateEnvironment(env: *std.process.EnvMap) !bool { try std.fmt.bufPrint(&sbuf, "/usr/lib/rofi:{s}/.local/lib/rofi", .{home}), ); - // PATH - { - var bufstream = std.io.fixedBufferStream(&buf); - var b = delimitedWriter(bufstream.writer(), ':'); - - for ([_][]const u8{ - ".nix-profile/bin", - ".mix/escripts", - ".cargo/bin", - ".local/bin", - "go/bin", - ".roswell/bin", - }) |fixed| { - try b.push(try std.fmt.bufPrint(&sbuf, "{s}/{s}", .{ home, fixed })); - } - - // racket bins - racket: { - try msg("acquiring racket binary path...", .{}); - const res = std.process.Child.run(.{ - .allocator = alloc, - .argv = &.{ - "racket", - "-l", - "racket/base", - "-e", - "(require setup/dirs) (display (path->string (find-user-console-bin-dir)))", - }, - }) catch break :racket; - defer alloc.free(res.stdout); - defer alloc.free(res.stderr); - - try b.push(res.stdout); - - log.info("racket binary path registered", .{}); - } - - if (env.get("PATH")) |system_path| { - try b.push(system_path); - } - - try env.put("PATH", bufstream.getWritten()); - } - // LUA_CPATH { var bufstream = std.io.fixedBufferStream(&buf); diff --git a/scripts/mzteinit/src/util.zig b/scripts/mzteinit/src/util.zig index 1222f75..af3c86d 100644 --- a/scripts/mzteinit/src/util.zig +++ b/scripts/mzteinit/src/util.zig @@ -47,9 +47,7 @@ pub fn fmtCommand(cmd: []const []const u8) std.fmt.Formatter(formatCommand) { return .{ .data = cmd }; } -pub fn findInPath(alloc: std.mem.Allocator, bin: []const u8) !?[]const u8 { - const path = std.posix.getenv("PATH") orelse return null; - +pub fn findInPath(alloc: std.mem.Allocator, path: []const u8, bin: []const u8) !?[]const u8 { var splits = std.mem.split(u8, path, ":"); while (splits.next()) |p| { const trimmed = std.mem.trim(u8, p, " \n\r");