Skip to content

feat: disable bash session history #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: oleg/lock-executables
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn main() {
// Necessary env var to substitute in the final artifact depends on, regardless of the
// build context; either in nix-shell or a basic nix build.

// We need to support non-nix environment anyways, ecpesially for VSCode and rust-analyser that
// We need to support non-nix environment anyways, especially for VSCode and rust-analyser that
// is being run by a VSCode extension and it doesn't have access to nix-shell to do a proper build.
if var("IN_NIX").is_err() || var("IN_NIX").unwrap() != "1" {
println!("cargo:rustc-env=CNS_ESSENTIALS=/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin:/opt/homebrew/bin:/opt/homebrew/sbin");
Expand Down
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,16 @@ fn cached_shell_env(pure: bool, inp: &NixShellInput) -> EnvOptions {
let bashopts = env.remove(OsStr::new("BASHOPTS")).unwrap_or_default();
env.insert(OsString::from("IN_CACHED_NIX_SHELL"), OsString::from("1"));

// Disable bash session history. See https://superuser.com/a/1400695 for details.
// Also, see /etc/bashrc_Apple_Terminal, to look at the script that does lookups for the
// SHELL_SESSION_DID_INIT env var.
if std::env::var("CNS_DONT_SET_SHELL_SESSION_DID_INIT").is_err() {
env.insert(
OsString::from("SHELL_SESSION_DID_INIT"),
OsString::from("1"),
);
}

EnvOptions {
env: merge_env(if pure { env } else { merge_impure_env(env) }),
shellopts,
Expand Down