config: command-arg to specify arguments to the executed command

Fixes #744
This commit is contained in:
Mitchell Hashimoto
2023-10-27 15:38:50 -07:00
parent 6db0d9c004
commit 9c56bd5dba
2 changed files with 26 additions and 15 deletions

View File

@ -268,6 +268,16 @@ palette: Palette = .{},
/// ///
command: ?[]const u8 = null, command: ?[]const u8 = null,
/// A single argument to pass to the command. This can be repeated to
/// pass multiple arguments. This slightly clunky configuration style is
/// so that Ghostty doesn't have to perform any sort of shell parsing
/// to find argument boundaries.
///
/// This cannot be used to override argv[0]. argv[0] will always be
/// set by Ghostty to be the command (possibly with a hyphen-prefix to
/// indicate that it is a login shell, depending on the OS).
@"command-arg": RepeatableString = .{},
/// The directory to change to after starting the command. /// The directory to change to after starting the command.
/// ///
/// The default is "inherit" except in special scenarios listed next. /// The default is "inherit" except in special scenarios listed next.

View File

@ -744,24 +744,25 @@ const Subprocess = struct {
env.remove("GHOSTTY_MAC_APP"); env.remove("GHOSTTY_MAC_APP");
} }
// If we're NOT in a flatpak (usually!), then we just exec the // Build our args list
// process directly. If we are in a flatpak, we use flatpak-spawn const args = args: {
// to escape the sandbox. const cap = 1 + opts.full_config.@"command-arg".list.items.len;
const args = if (!internal_os.isFlatpak()) try alloc.dupe( var args = try std.ArrayList([]const u8).initCapacity(alloc, cap);
[]const u8,
&[_][]const u8{argv0_override orelse path},
) else args: {
var args = try std.ArrayList([]const u8).initCapacity(alloc, 8);
defer args.deinit(); defer args.deinit();
// We run our shell wrapped in a /bin/sh login shell because if (!internal_os.isFlatpak()) {
// some systems do not properly initialize the env vars unless try args.append(argv0_override orelse path);
// we start this way (NixOS!) } else {
try args.append("/bin/sh"); // We run our shell wrapped in a /bin/sh login shell because
try args.append("-l"); // some systems do not properly initialize the env vars unless
try args.append("-c"); // we start this way (NixOS!)
try args.append(path); try args.append("/bin/sh");
try args.append("-l");
try args.append("-c");
try args.append(path);
}
try args.appendSlice(opts.full_config.@"command-arg".list.items);
break :args try args.toOwnedSlice(); break :args try args.toOwnedSlice();
}; };