From 6a2597a6d63b7bc823e8edb9d1fbdc5634876c81 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 5 Dec 2024 16:41:15 -0500 Subject: [PATCH 1/3] =?UTF-8?q?macos:=20Make=20"Settings=E2=80=A6"=20menu?= =?UTF-8?q?=20item=20open=20config=20file=20in=20Application=20Support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ...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. --- src/config/edit.zig | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/config/edit.zig b/src/config/edit.zig index 38d9f2b7f..e93d2a6f8 100644 --- a/src/config/edit.zig +++ b/src/config/edit.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const Allocator = std.mem.Allocator; const internal_os = @import("../os/main.zig"); @@ -6,7 +7,21 @@ const internal_os = @import("../os/main.zig"); /// paths the main config file could be in. pub fn open(alloc_gpa: Allocator) !void { // default location - const config_path = try internal_os.xdg.config(alloc_gpa, .{ .subdir = "ghostty/config" }); + var config_path = try internal_os.xdg.config(alloc_gpa, .{ .subdir = "ghostty/config" }); + + if (comptime builtin.os.tag == .macos) { + const xdg_config_exists = if (std.fs.accessAbsolute(config_path, std.fs.File.OpenFlags{})) true else |err| switch (err) { + error.BadPathName => false, + error.FileNotFound => false, + else => true, + }; + + if (!xdg_config_exists) { + alloc_gpa.free(config_path); + config_path = try internal_os.macos.appSupportDir(alloc_gpa, "config"); + } + } + defer alloc_gpa.free(config_path); // Create config directory recursively. From 79d84af56ee32d3f342a10e183d690923a115f1a Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 22 Dec 2024 08:52:38 -0500 Subject: [PATCH 2/3] comment --- src/config/edit.zig | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/config/edit.zig b/src/config/edit.zig index e93d2a6f8..ede13ee9d 100644 --- a/src/config/edit.zig +++ b/src/config/edit.zig @@ -7,21 +7,23 @@ const internal_os = @import("../os/main.zig"); /// paths the main config file could be in. pub fn open(alloc_gpa: Allocator) !void { // default location - var config_path = try internal_os.xdg.config(alloc_gpa, .{ .subdir = "ghostty/config" }); + const config_path = config_path: { + const xdg_config_path = try internal_os.xdg.config(alloc_gpa, .{ .subdir = "ghostty/config" }); - if (comptime builtin.os.tag == .macos) { - const xdg_config_exists = if (std.fs.accessAbsolute(config_path, std.fs.File.OpenFlags{})) true else |err| switch (err) { - error.BadPathName => false, - error.FileNotFound => false, - else => true, - }; + if (comptime builtin.os.tag == .macos) macos: { + if (std.fs.accessAbsolute(xdg_config_path, .{})) { + break :macos; + } else |err| switch (err) { + error.BadPathName, error.FileNotFound => {}, + else => break :macos, + } - if (!xdg_config_exists) { - alloc_gpa.free(config_path); - config_path = try internal_os.macos.appSupportDir(alloc_gpa, "config"); + alloc_gpa.free(xdg_config_path); + break :config_path try internal_os.macos.appSupportDir(alloc_gpa, "config"); } - } + break :config_path xdg_config_path; + }; defer alloc_gpa.free(config_path); // Create config directory recursively. From 44e1df5df3ae712986335dac20fd62cb4123e09f Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 22 Dec 2024 13:16:19 -0500 Subject: [PATCH 3/3] add a comment --- src/config/edit.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config/edit.zig b/src/config/edit.zig index ede13ee9d..692447594 100644 --- a/src/config/edit.zig +++ b/src/config/edit.zig @@ -11,6 +11,7 @@ pub fn open(alloc_gpa: Allocator) !void { const xdg_config_path = try internal_os.xdg.config(alloc_gpa, .{ .subdir = "ghostty/config" }); if (comptime builtin.os.tag == .macos) macos: { + // On macOS, use the application support path if the XDG path doesn't exists. if (std.fs.accessAbsolute(xdg_config_path, .{})) { break :macos; } else |err| switch (err) {