feat: allow opening project directories on the command line

This commit is contained in:
CJ van den Berg 2024-06-23 21:27:54 +02:00
parent 692e04b6a8
commit 1533ec2993
2 changed files with 37 additions and 2 deletions

View file

@ -41,6 +41,9 @@ pub fn open_cwd() tp.result {
pub fn open(rel_project_directory: []const u8) tp.result {
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
const project_directory = std.fs.cwd().realpath(rel_project_directory, &path_buf) catch "(none)";
var dir = std.fs.openDirAbsolute(project_directory, .{}) catch |e| return tp.exit_error(e);
dir.setAsCwd() catch |e| return tp.exit_error(e);
dir.close();
tp.env.get().str_set("project", project_directory);
return (try get()).pid.send(.{ "open", project_directory });
}