Skip to content

core: restructure args parsing to allow +-prefixed args after -e#11969

Open
jcollie wants to merge 1 commit intoghostty-org:mainfrom
jcollie:new-window-plus
Open

core: restructure args parsing to allow +-prefixed args after -e#11969
jcollie wants to merge 1 commit intoghostty-org:mainfrom
jcollie:new-window-plus

Conversation

@jcollie
Copy link
Copy Markdown
Member

@jcollie jcollie commented Mar 30, 2026

Previously, the argument parser would not allow +-prefixed args after -e. Depending on the situation, it would either raise an error about multiple actions found, or it would just skip the argument as if it wasn't there. In practice, it made commands like the following impossible:

ghostty -e hx +10 src/main.zig
ghostty +new-window -e vim src/main.zig '+normal!10Gvz5'

This PR changes argument parsing so that it stops looking for actions once an argument like -e has been seen. It also stores a copy of the arguments with the action filtered out so that subsequent operations that parse the CLI arguments again (like individual actions do) do not need to worry about filtering out actions.

This also parepares Ghostty for 0.16 a bit where the CLI arguments aren't available "at will" just by calling std.process.argsWithAllocator.

Fixes #11937

@jcollie jcollie marked this pull request as draft March 30, 2026 02:39
@jcollie jcollie marked this pull request as ready for review March 30, 2026 04:12
Copy link
Copy Markdown
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot here so its going to take me awhile to get to this.

If there is any way to break this down into smaller atomic chunks that would help. I'm getting caught up in balancing the (1) passed in iterator (2) fallback (3) special case mix of things.

The extra 5 lines of boilerplate (array list init + 4 line defer) is also a huge code smell to me that something is funky here, but obv just a smell. I don't understand the context enough to judge it completely yet.

I'll take a look at this, just wanted to give you the status.

@jcollie jcollie force-pushed the new-window-plus branch 3 times, most recently from db3dc6f to fe0ae2d Compare March 31, 2026 05:02
Previously, the argument parser would not allow `+`-prefixed args
after `-e`. Depending on the situation, it would either raise an error
about multiple actions found, or it would just skip the argument as
if it wasn't there. In practice, it made commands like the following
impossible:

```
ghostty -e hx +10 src/main.zig
```
```
ghostty +new-window -e vim src/main.zig '+normal!10Gvz5'
```

This PR changes argument parsing so that it stops looking for actions
once an argument like `-e` has been seen. It also stores a copy of the
arguments with the action filtered out so that subsequent operations
that parse the CLI arguments again (like individual actions do) do not
need to worry about filtering out actions.

This also parepares Ghostty for 0.16 a bit where the
CLI arguments aren't available "at will" just by calling
`std.process.argsWithAllocator`.

Fixes ghostty-org#11937
@jcollie jcollie mentioned this pull request Apr 12, 2026
10 tasks
@BirdeeHub
Copy link
Copy Markdown

Would this fix #12004 as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-e does not forward _all_ following arguments

3 participants