shell-integration: always call setupFeatures

Our existing logic already ensured that setupFeatures() was always
called, but that was happening from two code paths: explicitly when
shell integration is .none and implicitly via setup().

We can simplify this by always calling setupFeatures() once, outside of
the (automatic) shell integration path.

There's one small behavioral change: we previously didn't set up shell
features in the automatic shell integration path if we didn't have a
resources directory (as a side effect). Resources are required for shell
integrations, but we don't need them to export GHOSTTY_SHELL_FEATURES,
which could potentially still be useful on its on.
This commit is contained in:
Jon Parise
2025-12-23 12:59:58 -05:00
parent e56f28ac7b
commit 3d2aa9bd82
2 changed files with 9 additions and 15 deletions

View File

@@ -44,7 +44,6 @@ pub fn setup(
command: config.Command,
env: *EnvMap,
force_shell: ?Shell,
features: config.ShellIntegrationFeatures,
) !?ShellIntegration {
const exe = if (force_shell) |shell| switch (shell) {
.bash => "bash",
@@ -70,8 +69,6 @@ pub fn setup(
exe,
);
try setupFeatures(env, features);
return result;
}
@@ -161,7 +158,6 @@ test "force shell" {
.{ .shell = "sh" },
&env,
shell,
.{},
);
try testing.expectEqual(shell, result.?.shell);
}
@@ -183,11 +179,10 @@ test "shell integration failure" {
.{ .shell = "sh" },
&env,
null,
.{ .cursor = true, .title = false, .path = false },
);
try testing.expect(result == null);
try testing.expectEqualStrings("cursor", env.get("GHOSTTY_SHELL_FEATURES").?);
try testing.expectEqual(0, env.count());
}
/// Set up the shell integration features environment variable.
@@ -756,7 +751,7 @@ const TmpResourcesDir = struct {
path: []const u8,
shell_path: []const u8,
fn init(allocator: std.mem.Allocator, shell: Shell) !TmpResourcesDir {
fn init(allocator: Allocator, shell: Shell) !TmpResourcesDir {
var tmp_dir = std.testing.tmpDir(.{});
errdefer tmp_dir.cleanup();