Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

terminal: Skip SHLVL when loading login shell environment (#46273)

rari404466c7008e049
diff --git a/crates/util/src/util.rs b/crates/util/src/util.rs
index 5961089a3b2..9b099f04983 100644
--- a/crates/util/src/util.rs
+++ b/crates/util/src/util.rs
@@ -365,6 +365,13 @@ pub async fn load_login_shell_environment() -> Result<()> {
.await
.with_context(|| format!("capturing environment with {:?}", get_system_shell()))?
{
+ // Skip SHLVL to prevent it from polluting Zed's process environment.
+ // The login shell used for env capture increments SHLVL, and if we propagate it,
+ // terminals spawned by Zed will inherit it and increment again, causing SHLVL
+ // to start at 2 instead of 1 (and increase by 2 on each reload).
+ if name == "SHLVL" {
+ continue;
+ }
unsafe { env::set_var(&name, &value) };
}