mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Adding $EDITOR check for open
Allowing for users to set the $EDITOR variable and use it to open a file instead of the default on mac
This commit is contained in:
@ -19,27 +19,12 @@ pub fn open(
|
||||
url: []const u8,
|
||||
) !void {
|
||||
const cmd: OpenCommand = switch (builtin.os.tag) {
|
||||
.linux => .{ .child = std.process.Child.init(
|
||||
&.{ "xdg-open", url },
|
||||
alloc,
|
||||
) },
|
||||
|
||||
.linux => try determineOpenCommandLinux(alloc, url),
|
||||
.windows => .{ .child = std.process.Child.init(
|
||||
&.{ "rundll32", "url.dll,FileProtocolHandler", url },
|
||||
alloc,
|
||||
) },
|
||||
|
||||
.macos => .{
|
||||
.child = std.process.Child.init(
|
||||
switch (typ) {
|
||||
.text => &.{ "open", "-t", url },
|
||||
.unknown => &.{ "open", url },
|
||||
},
|
||||
alloc,
|
||||
),
|
||||
.wait = true,
|
||||
},
|
||||
|
||||
.macos => try determineOpenCommandMacOS(alloc, typ, url),
|
||||
.ios => return error.Unimplemented,
|
||||
else => @compileError("unsupported OS"),
|
||||
};
|
||||
@ -73,6 +58,33 @@ pub fn open(
|
||||
}
|
||||
}
|
||||
|
||||
fn determineOpenCommandLinux(alloc: Allocator, url: []const u8) !OpenCommand {
|
||||
const editor = std.process.getEnvVarOptional("EDITOR") orelse return .{ .child = std.process.Child.init(
|
||||
&.{ "xdg-open", url },
|
||||
alloc,
|
||||
) };
|
||||
|
||||
return .{ .child = std.process.Child.init(
|
||||
&.{ editor, url },
|
||||
alloc,
|
||||
) };
|
||||
}
|
||||
|
||||
fn determineOpenCommandMacOS(alloc: Allocator, typ: Type, url: []const u8) !OpenCommand {
|
||||
const editor = std.process.getEnvVarOptional("EDITOR") orelse return .{ .child = std.process.Child.init(
|
||||
switch (typ) {
|
||||
.text => &.{ "open", "-t", url },
|
||||
.unknown => &.{ "open", url },
|
||||
},
|
||||
alloc,
|
||||
) };
|
||||
|
||||
return .{ .child = std.process.Child.init(
|
||||
&.{ editor, url },
|
||||
alloc,
|
||||
) };
|
||||
}
|
||||
|
||||
const OpenCommand = struct {
|
||||
child: std.process.Child,
|
||||
wait: bool = false,
|
||||
|
Reference in New Issue
Block a user