Skip to content

Commit 44e1c0f

Browse files
authored
macos: Make "Settings…" menu item open config file in Application Sup… (#2895)
…port ...unless ~/.config/ghostty/config already exists, then that is opened. (Or whatever $XDG_CONFIG_HOME points to.) If both files exists, ghostty reads first the one in ~/.config/ghostty/config and then the one in Application Support, and merges the settings. In that case, the menu item opens the file at ~/.config. Fixes #2890.
2 parents 846660f + 44e1df5 commit 44e1c0f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/config/edit.zig

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
const std = @import("std");
2+
const builtin = @import("builtin");
23
const Allocator = std.mem.Allocator;
34
const internal_os = @import("../os/main.zig");
45

56
/// Open the configuration in the OS default editor according to the default
67
/// paths the main config file could be in.
78
pub fn open(alloc_gpa: Allocator) !void {
89
// default location
9-
const config_path = try internal_os.xdg.config(alloc_gpa, .{ .subdir = "ghostty/config" });
10+
const config_path = config_path: {
11+
const xdg_config_path = try internal_os.xdg.config(alloc_gpa, .{ .subdir = "ghostty/config" });
12+
13+
if (comptime builtin.os.tag == .macos) macos: {
14+
// On macOS, use the application support path if the XDG path doesn't exists.
15+
if (std.fs.accessAbsolute(xdg_config_path, .{})) {
16+
break :macos;
17+
} else |err| switch (err) {
18+
error.BadPathName, error.FileNotFound => {},
19+
else => break :macos,
20+
}
21+
22+
alloc_gpa.free(xdg_config_path);
23+
break :config_path try internal_os.macos.appSupportDir(alloc_gpa, "config");
24+
}
25+
26+
break :config_path xdg_config_path;
27+
};
1028
defer alloc_gpa.free(config_path);
1129

1230
// Create config directory recursively.

0 commit comments

Comments
 (0)