mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
config: remove command-arg
This commit is contained in:
@ -328,28 +328,15 @@ palette: Palette = .{},
|
|||||||
/// - SHELL environment variable
|
/// - SHELL environment variable
|
||||||
/// - passwd entry (user information)
|
/// - passwd entry (user information)
|
||||||
///
|
///
|
||||||
/// The command is the path to only the binary to run. This cannot
|
/// This can contain additional arguments to run the command with.
|
||||||
/// also contain arguments, because Ghostty does not perform any
|
/// If additional arguments are provided, the command will be executed
|
||||||
/// shell string parsing. To provide additional arguments, use the
|
/// using "/bin/sh -c". Ghostty does not do any shell command parsing.
|
||||||
/// "command-arg" configuration (repeated for multiple arguments).
|
|
||||||
///
|
///
|
||||||
/// If you're using the `ghostty` CLI there is also a shortcut
|
/// If you're using the `ghostty` CLI there is also a shortcut
|
||||||
/// to run a command with argumens directly: you can use the `-e`
|
/// to run a command with argumens directly: you can use the `-e`
|
||||||
/// flag. For example: `ghostty -e fish --with --custom --args`.
|
/// 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,
|
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 = .{},
|
|
||||||
|
|
||||||
/// Match a regular expression against the terminal text and associate
|
/// Match a regular expression against the terminal text and associate
|
||||||
/// clicking it with an action. This can be used to match URLs, file paths,
|
/// clicking it with an action. This can be used to match URLs, file paths,
|
||||||
/// etc. Actions can be opening using the system opener (i.e. "open" or
|
/// etc. Actions can be opening using the system opener (i.e. "open" or
|
||||||
@ -1644,10 +1631,17 @@ pub fn parseManuallyHook(self: *Config, alloc: Allocator, arg: []const u8, iter:
|
|||||||
// If it isn't "-e" then we just continue parsing normally.
|
// If it isn't "-e" then we just continue parsing normally.
|
||||||
if (!std.mem.eql(u8, arg, "-e")) return true;
|
if (!std.mem.eql(u8, arg, "-e")) return true;
|
||||||
|
|
||||||
// The first value is the command to run.
|
// Build up the command. We don't clean this up because we take
|
||||||
if (iter.next()) |command| {
|
// ownership in our allocator.
|
||||||
self.command = try alloc.dupe(u8, command);
|
var command = std.ArrayList(u8).init(alloc);
|
||||||
} else {
|
errdefer command.deinit();
|
||||||
|
|
||||||
|
while (iter.next()) |param| {
|
||||||
|
try command.appendSlice(param);
|
||||||
|
try command.append(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command.items.len == 0) {
|
||||||
try self._errors.add(alloc, .{
|
try self._errors.add(alloc, .{
|
||||||
.message = try std.fmt.allocPrintZ(
|
.message = try std.fmt.allocPrintZ(
|
||||||
alloc,
|
alloc,
|
||||||
@ -1659,11 +1653,7 @@ pub fn parseManuallyHook(self: *Config, alloc: Allocator, arg: []const u8, iter:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// All further arguments are parameters
|
self.command = command.items[0 .. command.items.len - 1];
|
||||||
self.@"command-arg".list.clearRetainingCapacity();
|
|
||||||
while (iter.next()) |param| {
|
|
||||||
try self.@"command-arg".parseCLI(alloc, param);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do not continue, we consumed everything.
|
// Do not continue, we consumed everything.
|
||||||
return false;
|
return false;
|
||||||
@ -1848,25 +1838,7 @@ test "parse e: command and args" {
|
|||||||
|
|
||||||
var it: TestIterator = .{ .data = &.{ "echo", "foo", "bar baz" } };
|
var it: TestIterator = .{ .data = &.{ "echo", "foo", "bar baz" } };
|
||||||
try testing.expect(!try cfg.parseManuallyHook(alloc, "-e", &it));
|
try testing.expect(!try cfg.parseManuallyHook(alloc, "-e", &it));
|
||||||
try testing.expectEqualStrings("echo", cfg.command.?);
|
try testing.expectEqualStrings("echo foo bar baz", cfg.command.?);
|
||||||
try testing.expectEqual(@as(usize, 2), cfg.@"command-arg".list.items.len);
|
|
||||||
try testing.expectEqualStrings("foo", cfg.@"command-arg".list.items[0]);
|
|
||||||
try testing.expectEqualStrings("bar baz", cfg.@"command-arg".list.items[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
test "parse e: command replaces args" {
|
|
||||||
const testing = std.testing;
|
|
||||||
var cfg = try Config.default(testing.allocator);
|
|
||||||
defer cfg.deinit();
|
|
||||||
const alloc = cfg._arena.?.allocator();
|
|
||||||
|
|
||||||
try cfg.@"command-arg".parseCLI(alloc, "foo");
|
|
||||||
try testing.expectEqual(@as(usize, 1), cfg.@"command-arg".list.items.len);
|
|
||||||
|
|
||||||
var it: TestIterator = .{ .data = &.{"echo"} };
|
|
||||||
try testing.expect(!try cfg.parseManuallyHook(alloc, "-e", &it));
|
|
||||||
try testing.expectEqualStrings("echo", cfg.command.?);
|
|
||||||
try testing.expectEqual(@as(usize, 0), cfg.@"command-arg".list.items.len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test "clone default" {
|
test "clone default" {
|
||||||
|
Reference in New Issue
Block a user