Fix environment loading with nushell (#35002)

Closes https://github.com/zed-industries/zed/issues/34739

I believe this is a regression introduced here:
- https://github.com/zed-industries/zed/pull/33599

Release Notes:

- Fixed a regression with loading environment variables in nushell
This commit is contained in:
Peter Tripp 2025-07-24 14:29:28 -04:00 committed by GitHub
parent 2d0f10c48a
commit 1f7ff956bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,10 +18,13 @@ pub fn capture(directory: &std::path::Path) -> Result<collections::HashMap<Strin
// In some shells, file descriptors greater than 2 cannot be used in interactive mode, // In some shells, file descriptors greater than 2 cannot be used in interactive mode,
// so file descriptor 0 (stdin) is used instead. This impacts zsh, old bash; perhaps others. // so file descriptor 0 (stdin) is used instead. This impacts zsh, old bash; perhaps others.
// See: https://github.com/zed-industries/zed/pull/32136#issuecomment-2999645482 // See: https://github.com/zed-industries/zed/pull/32136#issuecomment-2999645482
const ENV_OUTPUT_FD: std::os::fd::RawFd = 0; const FD_STDIN: std::os::fd::RawFd = 0;
let redir = match shell_name { const FD_STDOUT: std::os::fd::RawFd = 1;
Some("rc") => format!(">[1={}]", ENV_OUTPUT_FD), // `[1=0]`
_ => format!(">&{}", ENV_OUTPUT_FD), // `>&0` let (fd_num, redir) = match shell_name {
Some("rc") => (FD_STDIN, format!(">[1={}]", FD_STDIN)), // `[1=0]`
Some("nu") => (FD_STDOUT, "".to_string()),
_ => (FD_STDIN, format!(">&{}", FD_STDIN)), // `>&0`
}; };
command.stdin(Stdio::null()); command.stdin(Stdio::null());
command.stdout(Stdio::piped()); command.stdout(Stdio::piped());
@ -48,7 +51,7 @@ pub fn capture(directory: &std::path::Path) -> Result<collections::HashMap<Strin
super::set_pre_exec_to_start_new_session(&mut command); super::set_pre_exec_to_start_new_session(&mut command);
let (env_output, process_output) = spawn_and_read_fd(command, ENV_OUTPUT_FD)?; let (env_output, process_output) = spawn_and_read_fd(command, fd_num)?;
let env_output = String::from_utf8_lossy(&env_output); let env_output = String::from_utf8_lossy(&env_output);
anyhow::ensure!( anyhow::ensure!(