diff --git a/crates/nu-command/src/commands/classified/external.rs b/crates/nu-command/src/commands/classified/external.rs index 7299641453..569658717f 100644 --- a/crates/nu-command/src/commands/classified/external.rs +++ b/crates/nu-command/src/commands/classified/external.rs @@ -25,6 +25,7 @@ pub(crate) fn run_external_command( ) -> Result { trace!(target: "nu::run::external", "-> {}", command.name); + context.sync_path_to_env(); if !context.host.lock().is_external_cmd(&command.name) { return Err(ShellError::labeled_error( "Command not found", diff --git a/crates/nu-command/src/commands/run_external.rs b/crates/nu-command/src/commands/run_external.rs index 094b770b45..6e9ca6cb65 100644 --- a/crates/nu-command/src/commands/run_external.rs +++ b/crates/nu-command/src/commands/run_external.rs @@ -138,6 +138,7 @@ fn maybe_autocd_dir(cmd: &ExternalCommand, ctx: &mut EvaluationContext) -> Optio // - the command name ends in a path separator, or // - it's not a command on the path and no arguments were given. let name = &cmd.name; + ctx.sync_path_to_env(); let path_name = if name.ends_with(std::path::is_separator) || (cmd.args.is_empty() && PathBuf::from(name).is_dir() diff --git a/crates/nu-engine/src/evaluation_context.rs b/crates/nu-engine/src/evaluation_context.rs index ea6283378b..4b939fcabc 100644 --- a/crates/nu-engine/src/evaluation_context.rs +++ b/crates/nu-engine/src/evaluation_context.rs @@ -98,6 +98,17 @@ impl EvaluationContext { } } + pub fn sync_path_to_env(&self) { + let env_vars = self.scope.get_env_vars(); + + for (var, val) in env_vars { + if var == "PATH" || var == "Path" || var == "path" { + std::env::set_var(var, val); + break; + } + } + } + #[allow(unused)] pub(crate) fn get_command(&self, name: &str) -> Option { self.scope.get_command(name) diff --git a/crates/nu-engine/src/script.rs b/crates/nu-engine/src/script.rs index e9c39edc4d..77f1bcc8fd 100644 --- a/crates/nu-engine/src/script.rs +++ b/crates/nu-engine/src/script.rs @@ -101,6 +101,7 @@ pub fn process_script( }) .unwrap_or(""); + ctx.sync_path_to_env(); if internal_name == "run_external" && args .positional