shell-integration: always set up XDG_DATA_DIRS for nushell

This makes our 'ghostty' module available even if the rest of our
automatic integration steps fail, which is convenient for manual
"use"-age.

This is safe because autoload-ing our module doesn't have any side
effects other than cleaning up the XDG_DATA_DIRS environment variable.
This commit is contained in:
Jon Parise
2026-01-11 17:05:08 -05:00
parent 7e3c9f4d5a
commit 9434203725

View File

@@ -732,6 +732,11 @@ fn setupNushell(
resource_dir: []const u8,
env: *EnvMap,
) !?config.Command {
// Add our XDG_DATA_DIRS entry (for nushell/vendor/autoload/). This
// makes our 'ghostty' module automatically available, even if any
// of the later checks abort the rest of our automatic integration.
if (!try setupXdgDataDirs(alloc, resource_dir, env)) return null;
var stack_fallback = std.heap.stackFallback(4096, alloc);
var cmd = internal_os.shell.ShellCommandBuilder.init(stack_fallback.get());
defer cmd.deinit();
@@ -783,8 +788,6 @@ fn setupNushell(
}
}
if (!try setupXdgDataDirs(alloc, resource_dir, env)) return null;
// Return a copy of our modified command line to use as the shell command.
return .{ .shell = try alloc.dupeZ(u8, try cmd.toOwnedSlice()) };
}
@@ -836,7 +839,8 @@ test "nushell: unsupported options" {
defer env.deinit();
try testing.expect(try setupNushell(alloc, .{ .shell = cmdline }, res.path, &env) == null);
try testing.expectEqual(0, env.count());
try testing.expect(env.get("XDG_DATA_DIRS") != null);
try testing.expect(env.get("GHOSTTY_SHELL_INTEGRATION_XDG_DIR") != null);
}
}