From 5ea99d36262448deea80495fb03d60a028b6c8ad Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Sat, 20 Apr 2024 11:27:15 -0700 Subject: [PATCH] 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. --- src/termio.zig | 2 ++ src/termio/shell_integration.zig | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/termio.zig b/src/termio.zig index aec3aab23..45382cda1 100644 --- a/src/termio.zig +++ b/src/termio.zig @@ -16,4 +16,6 @@ pub const Impl = Exec; test { @import("std").testing.refAllDecls(@This()); + + _ = @import("termio/shell_integration.zig"); } diff --git a/src/termio/shell_integration.zig b/src/termio/shell_integration.zig index 95d86eaae..8693e7fce 100644 --- a/src/termio/shell_integration.zig +++ b/src/termio/shell_integration.zig @@ -29,8 +29,8 @@ pub fn setup( features: config.ShellIntegrationFeatures, ) !?Shell { const exe = if (force_shell) |shell| switch (shell) { - .fish => "/fish", - .zsh => "/zsh", + .fish => "fish", + .zsh => "zsh", } else std.fs.path.basename(command_path); const shell: Shell = shell: { @@ -123,3 +123,16 @@ fn setupZsh( ); 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, .{})); + } +}