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,
|
url: []const u8,
|
||||||
) !void {
|
) !void {
|
||||||
const cmd: OpenCommand = switch (builtin.os.tag) {
|
const cmd: OpenCommand = switch (builtin.os.tag) {
|
||||||
.linux => .{ .child = std.process.Child.init(
|
.linux => try determineOpenCommandLinux(alloc, url),
|
||||||
&.{ "xdg-open", url },
|
|
||||||
alloc,
|
|
||||||
) },
|
|
||||||
|
|
||||||
.windows => .{ .child = std.process.Child.init(
|
.windows => .{ .child = std.process.Child.init(
|
||||||
&.{ "rundll32", "url.dll,FileProtocolHandler", url },
|
&.{ "rundll32", "url.dll,FileProtocolHandler", url },
|
||||||
alloc,
|
alloc,
|
||||||
) },
|
) },
|
||||||
|
.macos => try determineOpenCommandMacOS(alloc, typ, url),
|
||||||
.macos => .{
|
|
||||||
.child = std.process.Child.init(
|
|
||||||
switch (typ) {
|
|
||||||
.text => &.{ "open", "-t", url },
|
|
||||||
.unknown => &.{ "open", url },
|
|
||||||
},
|
|
||||||
alloc,
|
|
||||||
),
|
|
||||||
.wait = true,
|
|
||||||
},
|
|
||||||
|
|
||||||
.ios => return error.Unimplemented,
|
.ios => return error.Unimplemented,
|
||||||
else => @compileError("unsupported OS"),
|
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 {
|
const OpenCommand = struct {
|
||||||
child: std.process.Child,
|
child: std.process.Child,
|
||||||
wait: bool = false,
|
wait: bool = false,
|
||||||
|
Reference in New Issue
Block a user