diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index eea99d6188..5440f9caa2 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -858,8 +858,6 @@ fn do_auto_cd( report_shell_error(engine_state, &err); return; }; - // Let PWD-per-drive sync with auto_cd target - let _ = nu_path::set_pwd_per_drive(PathBuf::from(path.clone()).as_path()); let cwd = Value::string(cwd, span); let shells = stack.get_env_var(engine_state, "NUSHELL_SHELLS"); diff --git a/crates/nu-command/src/filesystem/cd.rs b/crates/nu-command/src/filesystem/cd.rs index 6cecf56638..2af932bcb4 100644 --- a/crates/nu-command/src/filesystem/cd.rs +++ b/crates/nu-command/src/filesystem/cd.rs @@ -114,8 +114,6 @@ impl Command for Cd { //FIXME: this only changes the current scope, but instead this environment variable //should probably be a block that loads the information from the state in the overlay PermissionResult::PermissionOk => { - // Let PWD-per-drive sync with cd target - let _ = nu_path::set_pwd_per_drive(path.as_path()); stack.set_cwd(path)?; Ok(PipelineData::empty()) } diff --git a/crates/nu-path/src/pwd_per_drive.rs b/crates/nu-path/src/pwd_per_drive.rs index 1bd50f6bd9..e6d8dc3436 100644 --- a/crates/nu-path/src/pwd_per_drive.rs +++ b/crates/nu-path/src/pwd_per_drive.rs @@ -280,8 +280,9 @@ pub mod pwd_per_drive_singleton { use super::*; /// set_pwd_per_drive - /// record PWD for drive, path must be absolute path + /// On Windows, record PWD for drive, path must be absolute path /// return Ok(()) if succeeded, otherwise error message + /// Other platforms, return Ok(()) pub fn set_pwd_per_drive(_path: &Path) -> Result<(), String> { cfg_if::cfg_if! { if #[cfg(target_os="windows")] { @@ -317,7 +318,7 @@ pub mod pwd_per_drive_singleton { } cfg_if::cfg_if! { if #[cfg(target_os="windows")] { - /// Helper only used on windows, if input path is relative path + /// Helper only used on Windows, if input path is relative path /// with drive letter, it can be expanded with PWD-per-drive. fn need_expand_pwd_per_drive(_path: &Path) -> bool { if let Some(path_str) = _path.to_str() { diff --git a/crates/nu-protocol/src/engine/stack.rs b/crates/nu-protocol/src/engine/stack.rs index ddd1169513..b97e593d81 100644 --- a/crates/nu-protocol/src/engine/stack.rs +++ b/crates/nu-protocol/src/engine/stack.rs @@ -726,6 +726,8 @@ impl Stack { let path = nu_path::strip_trailing_slash(path); let value = Value::string(path.to_string_lossy(), Span::unknown()); self.add_env_var("PWD".into(), value); + // Sync with PWD-per-drive + let _ = nu_path::set_pwd_per_drive(&path); Ok(()) } } diff --git a/src/main.rs b/src/main.rs index 283556ecc4..78517b6e90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ use log::{trace, Level}; use miette::Result; use nu_cli::gather_parent_env_vars; use nu_lsp::LanguageServer; -use nu_path::{canonicalize_with, set_pwd_per_drive}; +use nu_path::canonicalize_with; use nu_protocol::{ engine::EngineState, report_shell_error, ByteStream, PipelineData, ShellError, Span, Spanned, Value, @@ -78,8 +78,8 @@ fn main() -> Result<()> { // Get the current working directory from the environment. let init_cwd = current_dir_from_environment(); - // Let PWD-per-drive sync from startup - let _ = set_pwd_per_drive(init_cwd.as_ref()); + // Sync with PWD-per-drive + let _ = nu_path::set_pwd_per_drive(init_cwd.as_ref()); // Custom additions let delta = {