Files
xsh/src/builtin/cmds/cd.zig
T

19 lines
536 B
Zig
Raw Normal View History

2026-08-23 11:11:36 +03:00
const std = @import("std");
2026-08-23 11:43:28 +03:00
const types = @import("../types.zig");
pub fn execute(ctx: types.BuiltinCommandContext) !void {
const path = if (ctx.argv.len >= 2)
ctx.argv[1]
2026-08-23 11:11:36 +03:00
else
2026-08-23 11:43:28 +03:00
ctx.shell.environ.get("USERPROFILE") orelse ctx.shell.environ.get("HOME") orelse {
2026-08-23 11:11:36 +03:00
std.debug.print("xsh: cd: cannot find home directory\n", .{});
return;
};
2026-08-23 11:43:28 +03:00
var dir = try std.Io.Dir.cwd().openDir(ctx.io, path, .{});
defer dir.close(ctx.io);
2026-08-23 11:11:36 +03:00
2026-08-23 11:43:28 +03:00
try std.process.setCurrentDir(ctx.io, dir);
2026-08-23 11:11:36 +03:00
}