From e92f8b28d5cf57c2d17de91e744f79846ac1f988 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 18 Dec 2023 12:38:14 -0600 Subject: [PATCH] cli: parse args as command when launched as 'xdg-terminal-exec' [xdg-terminal-exec](https://github.com/Vladimir-csp/xdg-terminal-exec) is a proposal to allow users to define a "default" terminal to use when launching applications which have `Terminal=true` in their desktop file. Users can symlink their terminal of choice to `xdg-terminal-exec`, which is the first option used in the GIO launch options, and is gaining traction elsewhere. When launched as `xdg-terminal-exec`, ghostty must parse any args as the command. Add a special case using the same logic as the '-e' flag to enable ghostty to be launched in this manner. Fixes: https://github.com/mitchellh/ghostty/issues/658 --- src/config/Config.zig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index 97a3b19a1..28acfaade 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -1630,7 +1630,9 @@ pub fn finalize(self: *Config) !void { /// Callback for src/cli/args.zig to allow us to handle special cases /// like `--help` or `-e`. Returns "false" if the CLI parsing should halt. pub fn parseManuallyHook(self: *Config, alloc: Allocator, arg: []const u8, iter: anytype) !bool { - if (std.mem.eql(u8, arg, "-e")) { + if (std.mem.eql(u8, arg, "-e") or + std.mem.eql(u8, std.fs.path.basename(arg), "xdg-terminal-exec")) + { // Build up the command. We don't clean this up because we take // ownership in our allocator. var command = std.ArrayList(u8).init(alloc); @@ -1645,8 +1647,8 @@ pub fn parseManuallyHook(self: *Config, alloc: Allocator, arg: []const u8, iter: try self._errors.add(alloc, .{ .message = try std.fmt.allocPrintZ( alloc, - "missing command after -e", - .{}, + "missing command after {s}", + .{arg}, ), });