macOS: open preferred config if exists (#12321)

This helps developers like me to use a separate config for debugging
(which is already supported by the environment variable
`GHOSTTY_CONFIG_PATH`).

I can already use the local scheme to load a debugging config file, but
when opening the config file through Ghostty, it will still open the
default config.

This changes doesn't affect the release build, since `configPath` is
only set in the DEBUG build.
This commit is contained in:
Mitchell Hashimoto
2026-04-21 09:23:29 -07:00
committed by GitHub
2 changed files with 11 additions and 5 deletions

View File

@@ -941,7 +941,7 @@ class AppDelegate: NSObject,
// MARK: - IB Actions
@IBAction func openConfig(_ sender: Any?) {
Ghostty.App.openConfig()
ghostty.openConfig()
}
@IBAction func reloadConfig(_ sender: Any?) {

View File

@@ -118,8 +118,14 @@ extension Ghostty {
ghostty_app_tick(app)
}
static func openConfig() {
let str = Ghostty.AllocatedString(ghostty_config_open_path()).string
private static func openConfig(_ app: ghostty_app_t) {
guard let app_ud = ghostty_app_userdata(app) else { return }
let app = Unmanaged<App>.fromOpaque(app_ud).takeUnretainedValue()
app.openConfig()
}
func openConfig() {
let str = configPath ?? Ghostty.AllocatedString(ghostty_config_open_path()).string
guard !str.isEmpty else { return }
#if os(macOS)
let fileURL = URL(fileURLWithPath: str).absoluteString
@@ -128,7 +134,7 @@ extension Ghostty {
fileURL.withCString { cStr in
action.url = cStr
action.len = UInt(fileURL.count)
_ = openURL(action)
_ = App.openURL(action)
}
#else
fatalError("Unsupported platform for opening config file")
@@ -549,7 +555,7 @@ extension Ghostty {
pwdChanged(app, target: target, v: action.action.pwd)
case GHOSTTY_ACTION_OPEN_CONFIG:
openConfig()
openConfig(app)
case GHOSTTY_ACTION_FLOAT_WINDOW:
toggleFloatWindow(app, target: target, mode: action.action.float_window)