Replace environment variable parser with zed --printenv outputting JSON (#32637)

Closes: https://github.com/zed-industries/zed/issues/32445
Follow-up to: https://github.com/zed-industries/zed/pull/31799

Release Notes:

- Improved handling of environment variables

---------

Co-authored-by: Conrad Irwin <conrad@zed.dev>
This commit is contained in:
Peter Tripp 2025-06-13 11:49:15 -04:00 committed by GitHub
parent d280c95d91
commit 71dbe88459
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 77 additions and 371 deletions

View file

@ -262,6 +262,26 @@ fn load_shell_from_passwd() -> Result<()> {
Ok(())
}
#[cfg(unix)]
/// Returns a shell escaped path for the current zed executable
pub fn get_shell_safe_zed_path() -> anyhow::Result<String> {
use anyhow::Context;
let zed_path = std::env::current_exe()
.context("Failed to determine current zed executable path.")?
.to_string_lossy()
.trim_end_matches(" (deleted)") // see https://github.com/rust-lang/rust/issues/69343
.to_string();
// As of writing, this can only be fail if the path contains a null byte, which shouldn't be possible
// but shlex has annotated the error as #[non_exhaustive] so we can't make it a compile error if other
// errors are introduced in the future :(
let zed_path_escaped =
shlex::try_quote(&zed_path).context("Failed to shell-escape Zed executable path.")?;
return Ok(zed_path_escaped.to_string());
}
#[cfg(unix)]
pub fn load_login_shell_environment() -> Result<()> {
load_shell_from_passwd().log_err();