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

19 lines
529 B
Zig

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