Ensure setup_features runs even when shell detection fails

This commit is contained in:
Bryan Lee
2025-01-15 08:30:40 +08:00
parent 6853a5423f
commit ccd6fd26ec

View File

@ -58,7 +58,21 @@ pub fn setup(
break :exe std.fs.path.basename(command[0..idx]); break :exe std.fs.path.basename(command[0..idx]);
}; };
const result: ShellIntegration = shell: { const result = try setupShell(alloc_arena, resource_dir, command, env, exe);
// Setup our feature env vars
try setupFeatures(env, features);
return result;
}
fn setupShell(
alloc_arena: Allocator,
resource_dir: []const u8,
command: []const u8,
env: *EnvMap,
exe: []const u8,
) !?ShellIntegration {
if (std.mem.eql(u8, "bash", exe)) { if (std.mem.eql(u8, "bash", exe)) {
// Apple distributes their own patched version of Bash 3.2 // Apple distributes their own patched version of Bash 3.2
// on macOS that disables the ENV-based POSIX startup path. // on macOS that disables the ENV-based POSIX startup path.
@ -80,7 +94,7 @@ pub fn setup(
resource_dir, resource_dir,
env, env,
) orelse return null; ) orelse return null;
break :shell .{ return .{
.shell = .bash, .shell = .bash,
.command = new_command, .command = new_command,
}; };
@ -88,7 +102,7 @@ pub fn setup(
if (std.mem.eql(u8, "elvish", exe)) { if (std.mem.eql(u8, "elvish", exe)) {
try setupXdgDataDirs(alloc_arena, resource_dir, env); try setupXdgDataDirs(alloc_arena, resource_dir, env);
break :shell .{ return .{
.shell = .elvish, .shell = .elvish,
.command = try alloc_arena.dupe(u8, command), .command = try alloc_arena.dupe(u8, command),
}; };
@ -96,7 +110,7 @@ pub fn setup(
if (std.mem.eql(u8, "fish", exe)) { if (std.mem.eql(u8, "fish", exe)) {
try setupXdgDataDirs(alloc_arena, resource_dir, env); try setupXdgDataDirs(alloc_arena, resource_dir, env);
break :shell .{ return .{
.shell = .fish, .shell = .fish,
.command = try alloc_arena.dupe(u8, command), .command = try alloc_arena.dupe(u8, command),
}; };
@ -104,19 +118,13 @@ pub fn setup(
if (std.mem.eql(u8, "zsh", exe)) { if (std.mem.eql(u8, "zsh", exe)) {
try setupZsh(resource_dir, env); try setupZsh(resource_dir, env);
break :shell .{ return .{
.shell = .zsh, .shell = .zsh,
.command = try alloc_arena.dupe(u8, command), .command = try alloc_arena.dupe(u8, command),
}; };
} }
return null; return null;
};
// Setup our feature env vars
try setupFeatures(env, features);
return result;
} }
test "force shell" { test "force shell" {