From 822c67b3e0f86a89a1391b448dcce509baff7a6f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 14 Nov 2023 16:58:27 -0800 Subject: [PATCH 1/2] termio/exec: fall back to default command if specified command not found Fixes #880 If a command is specified but it can't be found, then we try to fallback to a default command like "sh" and log the issue. This prevents Ghostty from simply exiting. --- src/termio/Exec.zig | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 85513ba91..fa85c53d4 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -722,13 +722,28 @@ const Subprocess = struct { const alloc = arena.allocator(); // Determine the path to the binary we're executing + const default_path = switch (builtin.os.tag) { + .windows => "cmd.exe", + else => "sh", + }; const path = try Command.expandPath( alloc, - opts.full_config.command orelse switch (builtin.os.tag) { - .windows => "cmd.exe", - else => "sh", - }, - ) orelse return error.CommandNotFound; + opts.full_config.command orelse default_path, + ) orelse path: { + // If we had a command specified, try to at least fall + // back to a default value like "sh" so that Ghostty + // launches. + if (opts.full_config.command) |command| { + log.warn("unable to find command, fallbacking back to default command={s}", .{command}); + if (try Command.expandPath( + alloc, + default_path, + )) |path| break :path path; + } + + log.warn("unable to find default command to launch, exiting", .{}); + return error.CommandNotFound; + }; // On macOS, we launch the program as a login shell. This is a Mac-specific // behavior (see other terminals). Terminals in general should NOT be From 83eff4e330b24a47e5cb87ca9e31d94288e882cd Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 14 Nov 2023 17:03:47 -0800 Subject: [PATCH 2/2] config: clarify that command can only be a single binary --- src/config/Config.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/config/Config.zig b/src/config/Config.zig index 82e09eb66..c13a76bef 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -278,6 +278,16 @@ palette: Palette = .{}, /// - SHELL environment variable /// - passwd entry (user information) /// +/// The command is the path to only the binary to run. This cannot +/// also contain arguments, because Ghostty does not perform any +/// shell string parsing. To provide additional arguments, use the +/// "command-arg" configuration (repeated for multiple arguments). +/// +/// If you're using the `ghostty` CLI there is also a shortcut +/// to run a command with argumens directly: you can use the `-e` +/// flag. For example: `ghostty -e fish --with --custom --args`. +/// This is just shorthand for specifying "command" and +/// "command-arg" in the configuration. command: ?[]const u8 = null, /// A single argument to pass to the command. This can be repeated to