mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-14 03:25:50 +00:00
macOS: expand tilde in file paths before opening (#10863)
## 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: ```swift 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 ```swift 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.
This commit is contained in:
@@ -694,7 +694,10 @@ extension Ghostty {
|
||||
if let candidate = URL(string: action.url), candidate.scheme != nil {
|
||||
url = candidate
|
||||
} else {
|
||||
url = URL(filePath: action.url)
|
||||
// Expand ~ to the user's home directory so that file paths
|
||||
// like ~/Documents/file.txt resolve correctly.
|
||||
let expandedPath = NSString(string: action.url).standardizingPath
|
||||
url = URL(filePath: expandedPath)
|
||||
}
|
||||
|
||||
switch action.kind {
|
||||
|
||||
Reference in New Issue
Block a user