summaryrefslogtreecommitdiff
path: root/src/cmd/path.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/path.zig')
-rw-r--r--src/cmd/path.zig67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/cmd/path.zig b/src/cmd/path.zig
new file mode 100644
index 0000000..734350a
--- /dev/null
+++ b/src/cmd/path.zig
@@ -0,0 +1,67 @@
+const std = @import("std");
+const Allocator = std.mem.Allocator;
+const print = std.debug.print;
+
+const types = @import("./types.zig");
+const CommandStatus = types.CommandStatus;
+const OutputCapture = types.OutputCapture;
+const InputSource = types.InputSource;
+
+pub const PathGet = struct {
+ pub fn eval(path_get: PathGet, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus {
+ _ = path_get;
+ _ = input_source;
+
+ const current_path = std.process.getEnvVarOwned(allocator, "PATH") catch |err| switch (err) {
+ error.EnvironmentVariableNotFound => {
+ // PATH not set, show empty
+ const output = "PATH=(not set)\n";
+ if (output_capture) |capture| {
+ try capture.write(output);
+ } else {
+ print("{s}", .{output});
+ }
+ return CommandStatus{ .Code = 0 };
+ },
+ else => {
+ const error_msg = "Cannot access PATH environment variable\n";
+ if (output_capture) |capture| {
+ try capture.write(error_msg);
+ } else {
+ print("{s}", .{error_msg});
+ }
+ return CommandStatus{ .Code = 1 };
+ },
+ };
+ defer allocator.free(current_path);
+
+ const output = try std.fmt.allocPrint(allocator, "PATH={s}\n", .{current_path});
+ defer allocator.free(output);
+ if (output_capture) |capture| {
+ try capture.write(output);
+ } else {
+ print("{s}", .{output});
+ }
+ return CommandStatus{ .Code = 0 };
+ }
+};
+
+pub const PathSet = struct {
+ value: []const u8,
+
+ pub fn eval(path_set: PathSet, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus {
+ _ = input_source;
+
+ // Note: In a real DOS system, this would persist for the session
+ // Here we just show what would be set but don't actually set it
+ // since Zig's std.process doesn't provide a simple way to set env vars
+ const output = try std.fmt.allocPrint(allocator, "PATH would be set to: {s}\n(Note: Environment variable setting not implemented in this shell)\n", .{path_set.value});
+ defer allocator.free(output);
+ if (output_capture) |capture| {
+ try capture.write(output);
+ } else {
+ print("{s}", .{output});
+ }
+ return CommandStatus{ .Code = 0 };
+ }
+};