diff options
author | 2021-08-17 01:44:30 -0700 | |
---|---|---|
committer | 2021-08-17 01:44:30 -0700 | |
commit | 574be79253f503fe3caedf5d66b1ff35f71a55d0 (patch) | |
tree | 1b55bb45d754a33428267834b75bd26ee1fa21fb /src/open.zig | |
parent | 209391d01c9fad548d5b84d8d0c530d317aa1d92 (diff) | |
download | bun-574be79253f503fe3caedf5d66b1ff35f71a55d0.tar.gz bun-574be79253f503fe3caedf5d66b1ff35f71a55d0.tar.zst bun-574be79253f503fe3caedf5d66b1ff35f71a55d0.zip |
alright thats the rename
Former-commit-id: 0faf61249e76382dfb1aa8721249474eae920753
Diffstat (limited to 'src/open.zig')
-rw-r--r-- | src/open.zig | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/open.zig b/src/open.zig new file mode 100644 index 000000000..d88cd5748 --- /dev/null +++ b/src/open.zig @@ -0,0 +1,26 @@ +usingnamespace @import("./global.zig"); +const std = @import("std"); +const alloc = @import("./alloc.zig"); + +const opener = switch (std.Target.current.os.tag) { + .macos => "/usr/bin/open", + .windows => "start", + else => "xdg-open", +}; + +pub fn openURL(url: string) !void { + if (comptime isWasi) { + Output.prettyln("-> {s}", .{url}); + Output.flush(); + return; + } + + var args_buf = [_]string{ opener, url }; + var child_process = try std.ChildProcess.init(&args_buf, alloc.dynamic); + child_process.stderr_behavior = .Pipe; + child_process.stdin_behavior = .Ignore; + child_process.stdout_behavior = .Pipe; + try child_process.spawn(); + _ = try child_process.wait(); + return; +} |