Skip to content

Comments

macOS: expand tilde in file paths before opening#10863

Merged
mitchellh merged 1 commit intoghostty-org:mainfrom
AlexFeijoo44:fix/macos-tilde-expansion-in-file-paths
Feb 21, 2026
Merged

macOS: expand tilde in file paths before opening#10863
mitchellh merged 1 commit intoghostty-org:mainfrom
AlexFeijoo44:fix/macos-tilde-expansion-in-file-paths

Conversation

@AlexFeijoo44
Copy link
Contributor

Summary

Cmd-clicking a file path containing ~ (e.g. ~/Documents/file.txt) fails to open the file on macOS because URL(filePath:) treats ~ as a literal directory name rather than the user's home directory.

This uses NSString.expandingTildeInPath to resolve ~ before constructing the file URL.

Root Cause

In openURL(), when the URL string has no scheme it falls through to:

url = URL(filePath: action.url)

Swift's URL(filePath:) does not perform tilde expansion. A path like ~/Documents/file.txt produces a URL pointing to a non-existent file, and NSWorkspace.open silently fails.

Fix

let expandedPath = NSString(string: action.url).expandingTildeInPath
url = URL(filePath: expandedPath)

Reproduction

  1. Have a terminal application (e.g. Claude Code) that outputs file paths with ~ prefixes
  2. Cmd-click the path in Ghostty on macOS
  3. The file does not open (fails silently)

With this fix, the path resolves correctly and opens in the default editor.

@AlexFeijoo44 AlexFeijoo44 requested a review from a team as a code owner February 19, 2026 16:39
@ghostty-vouch
Copy link
Contributor

ghostty-vouch bot commented Feb 19, 2026

Hi @AlexFeijoo44, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/ghostty-org/ghostty/blob/main/CONTRIBUTING.md for more details.

@mitchellh
Copy link
Contributor

!vouch

ghostty-vouch bot pushed a commit that referenced this pull request Feb 20, 2026
@ghostty-vouch ghostty-vouch bot mentioned this pull request Feb 20, 2026
ghostty-vouch bot added a commit that referenced this pull request Feb 20, 2026
Triggered by
[comment](#10863 (comment))
from @mitchellh.

Vouch: @AlexFeijoo44

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@mitchellh mitchellh reopened this Feb 20, 2026
Copy link
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.

Thanks, this simple change looks right to me.

`URL(filePath:)` treats `~` as a literal directory name, so
cmd-clicking a path like `~/Documents/file.txt` would fail to
open because the resulting file URL doesn't point to a real file.

Use `NSString.expandingTildeInPath` to resolve `~` to the user's
home directory before constructing the file URL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mitchellh mitchellh force-pushed the fix/macos-tilde-expansion-in-file-paths branch from ccc43b5 to b65261e Compare February 21, 2026 04:38
@mitchellh mitchellh merged commit 6ec8744 into ghostty-org:main Feb 21, 2026
59 checks passed
@github-actions github-actions bot added this to the 1.3.0 milestone Feb 21, 2026
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.

3 participants