Commit Graph

13385 Commits

Author SHA1 Message Date
Mitchell Hashimoto
4c2fb7ae0e Update mirror for direct deps 2025-12-13 13:53:46 -08:00
Mitchell Hashimoto
1805a9cb87 fix: explicitly allow preservation for TERMINFO in shell-integration (#9891)
Due to security issues, `sudo` implementations may not preserve
environment variables unless appended with `--preserve-env=list`.

Problem context: https://github.com/ghostty-org/ghostty/discussions/9861
2025-12-13 08:41:28 -08:00
Mitchell Hashimoto
0a6311c819 input: shift+backspace in Kitty with only disambiguate should do CSIu (#9896)
Fixes #9868 (shift+backspace part only)

You have to use `fish_key_reader -V` to verify this since it uses
different modes than Kitty's key reader. This matches the encoding to
Kitty.
2025-12-13 07:21:10 -08:00
Mitchell Hashimoto
c5d6b951e9 input: shift+backspace in Kitty with only disambiguate should do CSIu
Fixes #9868 (shift+backspace part only)
2025-12-13 07:18:22 -08:00
definfo
4a04efaff1 fix: explicitly allow preservation for TERMINFO in shell-integration
Due to security issues, `sudo` implementations may not preserve
environment variables unless appended with `--preserve-env=list`.

Signed-off-by: definfo <hjsdbb1@gmail.com>
2025-12-13 16:55:41 +08:00
Mitchell Hashimoto
7a1ff7779b feat: add readonly surface mode (#9130)
Tried my hand at #8432

Currently lacking tests and some sort of visual indicator that the
surface is locked.

Also, not entirely sure if I needed to touch `application.zig`.

Found what needed changing with help from Copilot (and added Docs w/
Copilot), but wrote most of the code myself.
2025-12-12 14:16:39 -08:00
Mitchell Hashimoto
182cb35bae core: remove readonly check 2025-12-12 14:15:43 -08:00
Mitchell Hashimoto
19e0864688 macos: unintended change 2025-12-12 14:14:15 -08:00
Mitchell Hashimoto
43b4ed5bc0 macos: only show readonly badge on AppKit 2025-12-12 14:12:05 -08:00
Mitchell Hashimoto
6dcf75126b macos: more strict detection for tab context menu (#9888)
We were accidentally modifying the "View" menu.
2025-12-12 14:09:39 -08:00
Mitchell Hashimoto
ddaf307cf7 macos: more strict detection for tab context menu
We were accidentally modifying the "View" menu.
2025-12-12 14:05:46 -08:00
Mitchell Hashimoto
22b8809858 macos: add a popover to the readonly badge with info 2025-12-12 14:02:45 -08:00
Mitchell Hashimoto
173d8efd90 macos: add to context menu 2025-12-12 13:55:03 -08:00
Mitchell Hashimoto
ceb1b5e587 macos: add a read-only menu item in View 2025-12-12 13:53:08 -08:00
Mitchell Hashimoto
ec2638b3c6 macos: readonly badge 2025-12-12 13:46:28 -08:00
Mitchell Hashimoto
dc7bc3014e add apprt action to notify apprt of surface readonly state 2025-12-12 13:13:54 -08:00
Mitchell Hashimoto
262b82ab08 fix(docs): window-decoration is now none instead of false (#9887)
Heya,
super random but i saw this in the documentation and felt like it should
be fixed 😅
2025-12-12 13:08:27 -08:00
Mitchell Hashimoto
0bf3642939 core: manage read-only through queueIo 2025-12-12 13:08:03 -08:00
Michael Hazan
6dd9a74e6e fix(docs): window-decoration is now none instead of false 2025-12-12 22:56:06 +02:00
Mitchell Hashimoto
c198c6dc69 fix: bash shell integration use-after-free bug from PR #9881 (#9885)
(Claude-generated content below)

## Fix bash shell integration use-after-free bug

### Problem

After updating to the latest `main` branch, Ghostty fails to launch with
bash shell integration enabled on Linux (Ubuntu 25.10). The terminal
window briefly appears and then closes with an error like:

```
/bin/sh: 1: ically: not found
```

The error message varies but typically contains fragments of words (like
"ically" from "automatically").

Related issue was possibly [reported in the comments of PR
#9881](https://github.com/ghostty-org/ghostty/pull/9881) shortly after
it was merged.

### Root Cause Analysis

The bug is a **use-after-free** in the bash shell integration setup.

In `setupBash()`, the `ShellCommandBuilder` is initialized with a
`stackFallback` allocator:

```zig
var stack_fallback = std.heap.stackFallback(4096, alloc);
var cmd = internal_os.shell.ShellCommandBuilder.init(stack_fallback.get());
```

When `cmd.toOwnedSlice()` is called, it returns a slice allocated from
the `stackFallback` allocator. Since the command string (e.g., "bash
--posix") easily fits within 4096 bytes, this memory is allocated on the
**stack**.

When `setupBash()` returns, the stack frame is deallocated, but the
returned `.shell` command still points to this now-invalid stack memory.
When the command is later used in `execCommand()` to build the `/bin/sh
-c "..."` invocation, it reads garbage data.

The garbage data often contains "ically" because it picks up fragments
from nearby memory—likely from the string literal "automatically" in the
comment on line 280:

```zig
// being manually sourced or automatically injected (from here).
```

This is a [known footgun with Zig's stackFallback
allocator](https://github.com/ziglang/zig/issues/16344) - memory
allocated from the stack portion becomes invalid once the stack frame is
exited.

### Bisect / Blame

The bug was introduced **~5 hours ago** (earlier today):

| Field | Value |
|-------|-------|
| **Commit** | `04fecd7c07fccad423ab1c33324a1997e142b6e2` |
| **PR** | [#9881](https://github.com/ghostty-org/ghostty/pull/9881)
(os/shell: introduce ShellCommandBuilder) |
| **Date** | Fri Dec 12 08:59:44 2025 -0500 |
| **Merged as** | `dd06d8a13` |

The previous implementation in commit `c0deaaba4` used
`std.mem.joinZ(alloc, " ", args.items)` which correctly allocated the
result using the arena allocator. The refactor to use
`ShellCommandBuilder` inadvertently changed the allocation strategy to
use stack memory for the returned value.

Other uses of `stackFallback` in the codebase are safe because they
either:
- Copy data to another allocator before the function returns (e.g.,
`env.put()` in `setupXdgDataDirs`)
- Use the data only within the function scope (e.g.,
`stream_handler.zig`)

### The Fix

Copy the command string to the arena allocator before returning:

```zig
const cmd_str = try cmd.toOwnedSlice();
return .{ .shell = try alloc.dupeZ(u8, cmd_str) };
```

This ensures the memory remains valid for the lifetime needed by the
caller, matching the behavior of other `stackFallback` usage patterns in
the codebase.

### Testing

- Verified the fix on Ubuntu 25.10 with Ghostty built from source
- Before fix: Terminal crashes immediately with "ically: not found"
error
- After fix: Terminal launches successfully with shell integration
working

```
info(io_exec): shell integration automatically injected shell=.bash
info(io_exec): started subcommand path=/bin/sh pid=...
info(surface): surface closed addr=...  # Normal close, no "abnormal process exit"
```

### Platform

Primarily affects Linux where `.shell` commands are wrapped in `/bin/sh
-c "..."`. macOS uses a different execution path via `login(1)`.
2025-12-12 12:11:06 -08:00
Mitchell Hashimoto
29fdb541d5 make all IO message queueing go through queueIo so we can intercept 2025-12-12 12:00:28 -08:00
Michael Bommarito
2d9c83dbb7 fix: bash shell integration use-after-free bug
The ShellCommandBuilder uses a stackFallback allocator, which means
toOwnedSlice() may return memory allocated on the stack. When setupBash()
returns, this stack memory becomes invalid, causing a use-after-free.

This manifested as garbage data in the shell command string, often
appearing as errors like "/bin/sh: 1: ically: not found" (where "ically"
was part of nearby memory, likely from the comment "automatically").

The fix copies the command string to the arena allocator before returning,
ensuring the memory remains valid for the lifetime of the command.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-12 13:36:36 -05:00
Mitchell Hashimoto
b58ac983cf docs changes 2025-12-12 07:29:46 -08:00
Matthew Hrehirchuk
6369aaa93e Merge branch 'main' of github.com:ghostty-org/ghostty into feat/read-only 2025-12-12 07:24:48 -08:00
Matthew Hrehirchuk
547bcd261d fix: removed apprt action for toggle_readonly 2025-12-12 07:24:22 -08:00
Matthew Hrehirchuk
12bb2f3f47 feat: add readonly surface mode 2025-12-12 07:24:22 -08:00
Mitchell Hashimoto
dd06d8a13b os/shell: introduce ShellCommandBuilder (#9881)
This builder is an efficient way to construct space-separated shell
command strings.

We use it in setupBash to avoid using an intermediate array of arguments
to construct our bash command line.
2025-12-12 07:09:58 -08:00
Mitchell Hashimoto
c95801db85 CONTRIBUTING: limit AI assistance to code only (#9882)
I think at this point all moderators and helpers can agree with me in
that LLM-generated responses are a blight upon this Earth.

Also probably worth putting in a clause against AI-generated assets
2025-12-12 07:09:35 -08:00
Jon Parise
04fecd7c07 os/shell: introduce ShellCommandBuilder
This builder is an efficient way to construct space-separated shell
command strings.

We use it in setupBash to avoid using an intermediate array of arguments
to construct our bash command line.
2025-12-12 08:59:44 -05:00
Leah Amelia Chen
315c8852a8 CONTRIBUTING: reorganize paragraphs 2025-12-12 18:59:22 +08:00
Leah Amelia Chen
8a1bb215c1 CONTRIBUTING: further clarifications 2025-12-12 18:56:24 +08:00
Leah Amelia Chen
5e049e1b3a CONTRIBUTING: AI-assisted != AI-generated 2025-12-12 18:53:10 +08:00
Leah Amelia Chen
65539d0d54 CONTRIBUTING: limit AI assistance to code only
I think at this point all moderators and helpers can agree with me in
that LLM-generated responses are a blight upon this Earth.

Also probably worth putting in a clause against AI-generated assets
(cf. the Commit Goods situation)
2025-12-12 18:43:51 +08:00
Mitchell Hashimoto
5aefb4b0a8 build(deps): bump cachix/install-nix-action from 31.8.4 to 31.9.0 (#9877)
Bumps
[cachix/install-nix-action](https://github.com/cachix/install-nix-action)
from 31.8.4 to 31.9.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/cachix/install-nix-action/releases">cachix/install-nix-action's
releases</a>.</em></p>
<blockquote>
<h2>v31.9.0</h2>
<h2>What's Changed</h2>
<ul>
<li>nix: 2.32.4 -&gt; 2.33.0 by <a
href="https://github.com/github-actions"><code>@​github-actions</code></a>[bot]
in <a
href="https://redirect.github.com/cachix/install-nix-action/pull/264">cachix/install-nix-action#264</a></li>
<li>chore(deps): bump peter-evans/create-pull-request from 7 to 8 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a>[bot]
in <a
href="https://redirect.github.com/cachix/install-nix-action/pull/263">cachix/install-nix-action#263</a></li>
<li>chore(deps): bump actions/checkout from 5 to 6 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a>[bot]
in <a
href="https://redirect.github.com/cachix/install-nix-action/pull/262">cachix/install-nix-action#262</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/cachix/install-nix-action/compare/v31.8.4...v31.9.0">https://github.com/cachix/install-nix-action/compare/v31.8.4...v31.9.0</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="4e002c8ec8"><code>4e002c8</code></a>
Merge pull request <a
href="https://redirect.github.com/cachix/install-nix-action/issues/262">#262</a>
from cachix/dependabot/github_actions/actions/checkout-6</li>
<li><a
href="65fe36965b"><code>65fe369</code></a>
Merge pull request <a
href="https://redirect.github.com/cachix/install-nix-action/issues/263">#263</a>
from cachix/dependabot/github_actions/peter-evans/cre...</li>
<li><a
href="c61d28fbcf"><code>c61d28f</code></a>
Merge pull request <a
href="https://redirect.github.com/cachix/install-nix-action/issues/264">#264</a>
from cachix/create-pull-request/patch</li>
<li><a
href="72e7d4072f"><code>72e7d40</code></a>
nix: 2.32.4 -&gt; 2.33.0</li>
<li><a
href="15a7ab2c66"><code>15a7ab2</code></a>
chore(deps): bump peter-evans/create-pull-request from 7 to 8</li>
<li><a
href="523410fd45"><code>523410f</code></a>
chore(deps): bump actions/checkout from 5 to 6</li>
<li><a
href="7e5978947b"><code>7e59789</code></a>
ci: drop macos-13 runner</li>
<li>See full diff in <a
href="0b0e072294...4e002c8ec8">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=cachix/install-nix-action&package-manager=github_actions&previous-version=31.8.4&new-version=31.9.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>
2025-12-11 16:54:02 -08:00
Mitchell Hashimoto
cba82e976c macOS: Change Tab Title (#9879)
This adds the ability to change a _tab_ title. The previous
functionality was tied to a specific _surface_. A tab title will stick
to the current tab regardless of active splits and so on.

This follows the nomenclature that macOS terminal app does which is
"title vs terminal title" (although we explicitly use "tab" in various
places, I may remove that in the future).

**This is macOS only. GTK is tracked here: #9880**. I did macOS only
because thats the machine I'm on. It'll be trivial to add this to GTK,
too.

## Demo


https://github.com/user-attachments/assets/d9446785-d919-4212-8553-db50c56c8c2f

(The option is also in the main menu, the context menu, and the command
palette)

## AI Disclosure

This PR was done fully with Amp, I didn't write a single line of code at
the time of writing this PR description. I reviewed everything though
and fully understand it all. Its a mimic more or less of the prompt
surface title work (although we did unify some stuff like the apprt
action).
2025-12-11 16:53:50 -08:00
Mitchell Hashimoto
50bbced0c9 macos: add title override to restorable state 2025-12-11 16:40:09 -08:00
Mitchell Hashimoto
6105344c31 macos: add change tab title to right click menu 2025-12-11 16:30:06 -08:00
Mitchell Hashimoto
65c5e72d3e macos: add tab title change to tab context menu 2025-12-11 16:24:50 -08:00
Mitchell Hashimoto
7b48eb5c62 macos: add change tab title to menu 2025-12-11 16:16:12 -08:00
Mitchell Hashimoto
65cf124e2c core: change apprt action to enum value instead of a new one 2025-12-11 16:09:45 -08:00
dependabot[bot]
1f05625d3f build(deps): bump cachix/install-nix-action from 31.8.4 to 31.9.0
Bumps [cachix/install-nix-action](https://github.com/cachix/install-nix-action) from 31.8.4 to 31.9.0.
- [Release notes](https://github.com/cachix/install-nix-action/releases)
- [Changelog](https://github.com/cachix/install-nix-action/blob/master/RELEASE.md)
- [Commits](0b0e072294...4e002c8ec8)

---
updated-dependencies:
- dependency-name: cachix/install-nix-action
  dependency-version: 31.9.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-12 00:06:57 +00:00
Mitchell Hashimoto
e93a4a911f macos: implement prompt_tab_title 2025-12-11 16:03:30 -08:00
Mitchell Hashimoto
32033c9e1a core: prompt_tab_title binding and apprt action 2025-12-11 16:03:19 -08:00
Mitchell Hashimoto
2448a90c30 bash: use a shell command for shell integration (#9875)
Prior to #7044, on macOS, our shell-integrated command line would be
executed under `exec -l`, which causes bash to be started as a login
shell. This matches the macOS platform norms.

The change to direct command execution meant that we'd skip that path,
and bash would start as a normal interactive (non-login) shell on macOS.
We fixed this in #7253 by adding `--login` to the `bash` direct command
on macOS.

This avoided some of the overhead of starting an extra process just to
get a login shell, but it unfortunately doesn't quite match the bash
environment we get when shell integration isn't enabled (namely, `$0`
doesn't get the login-shell-identifying `-` prefix).

Instead, this change implements the approach proposed in #7254, which
switches the bash shell integration path to use a `.shell` command,
giving us the same execution environment as the non-shell-integrated
command.
2025-12-11 15:41:29 -08:00
Mitchell Hashimoto
4d757f0f28 macos: show tab color as header for menu item so its not grey 2025-12-11 14:43:26 -08:00
Mitchell Hashimoto
89bdee447f macos: selected color in tab color menu should use target's color 2025-12-11 14:33:50 -08:00
Mitchell Hashimoto
d77b7c32f9 feat(macos): add tab color picker to tab context menu (#9784)
<img width="1824" height="1488" alt="image"
src="https://github.com/user-attachments/assets/4a77f743-9eae-40bf-8cb4-d45d884a85a5"
/>
2025-12-11 14:27:25 -08:00
Mitchell Hashimoto
2331e17835 macos: change tab color label to circle 2025-12-11 14:18:57 -08:00
Jon Parise
c0deaaba4e bash: use a shell command for shell integration
Prior to #7044, on macOS, our shell-integrated command line would be
executed under exec -l, which causes bash to be started as a login
shell. This matches the macOS platform norms.

The change to direct command execution meant that we'd skip that path,
and bash would start as a normal interactive (non-login) shell on macOS.
We fixed this in #7253 by adding `--login` to the `bash` direct command
on macOS.

This avoided some of the overhead of starting an extra process just to
get a login shell, but it unfortunately doesn't quite match the bash
environment we get when shell integration isn't enabled (namely, $0
doesn't get the login-shell-identifying "-" prefix).

Instead, this change implements the approach proposed in #7254, which
switches the bash shell integration path to use a .shell command, giving
us the same execution environment as the non-shell-integrated command.
2025-12-11 17:02:14 -05:00
Mitchell Hashimoto
6332fb5c01 macos: some cleanup 2025-12-11 13:59:06 -08:00