os: Add extra sentinel for GHOSTTY_RESOURCES_DIR (#6814)

Discover resourcesdir with `terminfo/g/ghostty`
as well as existing `terminfo/x/xterm-ghostty`.
This allows either terminfo file to be installed,
notably ncurses only provides a `terminfo/g/ghostty`.

It was brought up that the `ncurses-term` package on Fedora 42 at
<https://packages.fedoraproject.org/pkgs/ncurses/ncurses-term/fedora-42.html>
now provides a `/g/ghostty` terminfo entry which conflicts with
installing the similarly named file from ghostty's build process.
However a build with `zig build -Demit-terminfo=false` won't work as the
`x/xterm-ghostty` terminfo entry is used as a sentinel to discover the
`GHOSTTY_RESOURCES_DIR` used as a reference path for finding locale and
theme files.

```
src/Surface.zig|546 col 43| .resources_dir = global_state.resources_dir,
src/cli/list_themes.zig|112 col 22| if (global_state.resources_dir == null)
src/global.zig|38 col 5| resources_dir: ?[]const u8,
src/global.zig|173 col 14| self.resources_dir = try internal_os.resourcesDir(self.alloc);
src/global.zig|174 col 27| errdefer if (self.resources_dir) |dir| self.alloc.free(dir);
src/global.zig|177 col 18| if (self.resources_dir) |v| internal_os.i18n.init(v) catch |err| {
src/global.zig|185 col 18| if (self.resources_dir) |dir| self.alloc.free(dir);
```

We also have some comments that intend to change how the terminfo
database is discovered.

https://github.com/ghostty-org/ghostty/blob/main/src/termio/Exec.zig#L776C1-L781C60
This commit is contained in:
Mitchell Hashimoto 2025-03-19 09:04:17 -07:00 committed by GitHub
commit bd315c8394
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -29,10 +29,10 @@ pub fn resourcesDir(alloc: std.mem.Allocator) !?[]const u8 {
// This is the sentinel value we look for in the path to know
// we've found the resources directory.
const sentinel = switch (comptime builtin.target.os.tag) {
.windows => "terminfo/ghostty.terminfo",
.macos => "terminfo/78/xterm-ghostty",
else => "terminfo/x/xterm-ghostty",
const sentinels = switch (comptime builtin.target.os.tag) {
.windows => .{"terminfo/ghostty.terminfo"},
.macos => .{"terminfo/78/xterm-ghostty"},
else => .{ "terminfo/g/ghostty", "terminfo/x/xterm-ghostty" },
};
// Get the path to our running binary
@ -47,16 +47,20 @@ pub fn resourcesDir(alloc: std.mem.Allocator) !?[]const u8 {
// On MacOS, we look for the app bundle path.
if (comptime builtin.target.os.tag.isDarwin()) {
if (try maybeDir(&dir_buf, dir, "Contents/Resources", sentinel)) |v| {
return try std.fs.path.join(alloc, &.{ v, "ghostty" });
inline for (sentinels) |sentinel| {
if (try maybeDir(&dir_buf, dir, "Contents/Resources", sentinel)) |v| {
return try std.fs.path.join(alloc, &.{ v, "ghostty" });
}
}
}
// On all platforms, we look for a /usr/share style path. This
// is valid even on Mac since there is nothing that requires
// Ghostty to be in an app bundle.
if (try maybeDir(&dir_buf, dir, "share", sentinel)) |v| {
return try std.fs.path.join(alloc, &.{ v, "ghostty" });
inline for (sentinels) |sentinel| {
if (try maybeDir(&dir_buf, dir, "share", sentinel)) |v| {
return try std.fs.path.join(alloc, &.{ v, "ghostty" });
}
}
}