termio: fix "forced" shell integration

When a shell is forced, we would supply its /-prefixed executable name
to mimic a path location. The rest of the integration detection logic
assumes just a base executable name. Fix the forced names accordingly.

Also add a unit test for this "force shell" behavior.
This commit is contained in:
Jon Parise
2024-04-20 11:27:15 -07:00
parent 2624d3a753
commit 5ea99d3626
2 changed files with 17 additions and 2 deletions

View File

@ -16,4 +16,6 @@ pub const Impl = Exec;
test { test {
@import("std").testing.refAllDecls(@This()); @import("std").testing.refAllDecls(@This());
_ = @import("termio/shell_integration.zig");
} }

View File

@ -29,8 +29,8 @@ pub fn setup(
features: config.ShellIntegrationFeatures, features: config.ShellIntegrationFeatures,
) !?Shell { ) !?Shell {
const exe = if (force_shell) |shell| switch (shell) { const exe = if (force_shell) |shell| switch (shell) {
.fish => "/fish", .fish => "fish",
.zsh => "/zsh", .zsh => "zsh",
} else std.fs.path.basename(command_path); } else std.fs.path.basename(command_path);
const shell: Shell = shell: { const shell: Shell = shell: {
@ -123,3 +123,16 @@ fn setupZsh(
); );
try env.put("ZDOTDIR", integ_dir); try env.put("ZDOTDIR", integ_dir);
} }
test "force shell" {
const testing = std.testing;
const alloc = testing.allocator;
var env = EnvMap.init(alloc);
defer env.deinit();
inline for (@typeInfo(Shell).Enum.fields) |field| {
const shell = @field(Shell, field.name);
try testing.expectEqual(shell, setup(alloc, ".", "sh", &env, shell, .{}));
}
}