From 7dbcace8393fa05d53224c75dede3472c2d60802 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Wed, 3 Apr 2024 09:34:17 +0200 Subject: [PATCH] Fix accidentally dropping shell environment variable (#10105) Previously this code would run the changed commend, take its output, remove the `marker` from the front and then split on `0` byte. Problem was that `echo` adds a newline, which we did *NOT* skip. So whatever `env` printed as the first environment variable would have a `\n` in front of it. Instead of setting, say, `HOME`, Zed would set `\nHOME`. This change fixes the issue by switching to `printf '%s' marker`, which is more portable than using `echo -n`. This is related to https://github.com/zed-industries/zed/issues/9786 but I'm not sure yet whether that fixes it. Release Notes: - Fixed Zed sometimes missing environment variables from shell in case they were the first environment variable listed by `/usr/bin/env`. --- crates/project/src/project.rs | 2 +- crates/zed/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index ddff16fd5b4c1fd4858c2e44260f53987f70734e..4d5598621b865bc14f22ae33fb45e4bd7ff17579 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -10017,7 +10017,7 @@ async fn load_shell_environment(dir: &Path) -> Result> { }); let command = format!( - "cd '{}';{} echo {marker}; /usr/bin/env -0; exit 0;", + "cd '{}';{} printf '%s' {marker}; /usr/bin/env -0; exit 0;", dir.display(), additional_command.unwrap_or("") ); diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index dac37ba7f0ae50ad007d71213e6ec4e1aad768f3..c3a3367c0825615f3075ace0ae21d724c5d6ecc4 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -906,7 +906,7 @@ async fn load_login_shell_environment() -> Result<()> { // We still don't know why `$SHELL -l -i -c '/usr/bin/env -0'` would // do that, but it does, and `exit 0` helps. let shell_cmd = format!( - "{}echo {marker}; /usr/bin/env -0; exit 0;", + "{}printf '%s' {marker}; /usr/bin/env -0; exit 0;", shell_cmd_prefix.as_deref().unwrap_or("") );