bash: preserve an existing ENV value (#7908)

This commit is contained in:
Jon Parise
2025-07-10 19:06:31 -04:00
committed by GitHub
2 changed files with 27 additions and 0 deletions

View File

@ -26,6 +26,12 @@ if [ -n "$GHOSTTY_BASH_INJECT" ]; then
builtin declare __ghostty_bash_flags="$GHOSTTY_BASH_INJECT" builtin declare __ghostty_bash_flags="$GHOSTTY_BASH_INJECT"
builtin unset ENV GHOSTTY_BASH_INJECT builtin unset ENV GHOSTTY_BASH_INJECT
# Restore an existing ENV that was replaced by the shell integration code.
if [[ -n "$GHOSTTY_BASH_ENV" ]]; then
builtin export ENV=$GHOSTTY_BASH_ENV
builtin unset GHOSTTY_BASH_ENV
fi
# Restore bash's default 'posix' behavior. Also reset 'inherit_errexit', # Restore bash's default 'posix' behavior. Also reset 'inherit_errexit',
# which doesn't happen as part of the 'posix' reset. # which doesn't happen as part of the 'posix' reset.
builtin set +o posix builtin set +o posix

View File

@ -340,6 +340,11 @@ fn setupBash(
} }
} }
// Preserve an existing ENV value. We're about to overwrite it.
if (env.get("ENV")) |v| {
try env.put("GHOSTTY_BASH_ENV", v);
}
// Set our new ENV to point to our integration script. // Set our new ENV to point to our integration script.
var path_buf: [std.fs.max_path_bytes]u8 = undefined; var path_buf: [std.fs.max_path_bytes]u8 = undefined;
const integ_dir = try std.fmt.bufPrint( const integ_dir = try std.fmt.bufPrint(
@ -502,6 +507,22 @@ test "bash: HISTFILE" {
} }
} }
test "bash: ENV" {
const testing = std.testing;
var arena = ArenaAllocator.init(testing.allocator);
defer arena.deinit();
const alloc = arena.allocator();
var env = EnvMap.init(alloc);
defer env.deinit();
try env.put("ENV", "env.sh");
_ = try setupBash(alloc, .{ .shell = "bash" }, ".", &env);
try testing.expectEqualStrings("./shell-integration/bash/ghostty.bash", env.get("ENV").?);
try testing.expectEqualStrings("env.sh", env.get("GHOSTTY_BASH_ENV").?);
}
test "bash: additional arguments" { test "bash: additional arguments" {
const testing = std.testing; const testing = std.testing;
var arena = ArenaAllocator.init(testing.allocator); var arena = ArenaAllocator.init(testing.allocator);