mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
macos: add our application bundle to XDG_DATA_DIRS (#2974)
We're packaging more and more application-specific data directories in our application bundle. It's helpful to add that path to XDG_DATA_DIRS so those applications (that support XDG_DATA_DIRS) can locate their data directories without additional user-level configuration. This also fixes a typo ("MATHPATH") in the nearby MANPATH-building code.
This commit is contained in:
@ -794,26 +794,42 @@ const Subprocess = struct {
|
||||
}
|
||||
}
|
||||
|
||||
// Add the man pages from our application bundle to MANPATH.
|
||||
if (comptime builtin.target.isDarwin()) {
|
||||
if (cfg.resources_dir) |resources_dir| man: {
|
||||
var buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||
const dir = std.fmt.bufPrint(&buf, "{s}/../man", .{resources_dir}) catch |err| {
|
||||
log.warn("error building manpath, man pages may not be available err={}", .{err});
|
||||
break :man;
|
||||
};
|
||||
// On macOS, export additional data directories from our
|
||||
// application bundle.
|
||||
if (comptime builtin.target.isDarwin()) darwin: {
|
||||
const resources_dir = cfg.resources_dir orelse break :darwin;
|
||||
|
||||
var buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||
|
||||
const xdg_data_dir_key = "XDG_DATA_DIRS";
|
||||
if (std.fmt.bufPrint(&buf, "{s}/..", .{resources_dir})) |data_dir| {
|
||||
try env.put(
|
||||
xdg_data_dir_key,
|
||||
try internal_os.appendEnv(
|
||||
alloc,
|
||||
env.get(xdg_data_dir_key) orelse "/usr/local/share:/usr/share",
|
||||
data_dir,
|
||||
),
|
||||
);
|
||||
} else |err| {
|
||||
log.warn("error building {s}; err={}", .{ xdg_data_dir_key, err });
|
||||
}
|
||||
|
||||
const manpath_key = "MANPATH";
|
||||
if (std.fmt.bufPrint(&buf, "{s}/../man", .{resources_dir})) |man_dir| {
|
||||
// Always append with colon in front, as it mean that if
|
||||
// `MANPATH` is empty, then it should be treated as an extra
|
||||
// path instead of overriding all paths set by OS.
|
||||
try env.put(
|
||||
"MANPATH",
|
||||
manpath_key,
|
||||
try internal_os.appendEnvAlways(
|
||||
alloc,
|
||||
env.get("MATHPATH") orelse "",
|
||||
dir,
|
||||
env.get(manpath_key) orelse "",
|
||||
man_dir,
|
||||
),
|
||||
);
|
||||
} else |err| {
|
||||
log.warn("error building {s}; man pages may not be available; err={}", .{ manpath_key, err });
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user