diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index d0ce1ab9d9..f37e127941 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -397,14 +397,25 @@ impl ExternalCommand { /// Spawn a command without shelling out to an external shell pub fn spawn_simple_command(&self, cwd: &str) -> Result { - let head = trim_enclosing_quotes(&self.name.item); - let head = if head.starts_with('~') || head.starts_with("..") { - nu_path::expand_path_with(head, cwd) - .to_string_lossy() - .to_string() - } else { - head + let is_path = |arg: &str| { + let head = match arg.split_once(::std::path::is_separator) { + Some((x, _)) => x, + None => arg, + }; + head == "~" || head.chars().all(|ch| ch == '.') }; + let expand_path = |arg: String| { + if is_path(&arg) { + nu_path::expand_path_with(arg, cwd) + .to_string_lossy() + .to_string() + } else { + arg + } + }; + + let head = trim_enclosing_quotes(&self.name.item); + let head = expand_path(head); let mut process = std::process::Command::new(&head); @@ -413,13 +424,7 @@ impl ExternalCommand { item: trim_enclosing_quotes(&arg.item), span: arg.span, }; - arg.item = if arg.item.starts_with('~') || arg.item.starts_with("..") { - nu_path::expand_path_with(&arg.item, cwd) - .to_string_lossy() - .to_string() - } else { - arg.item - }; + arg.item = expand_path(arg.item); let cwd = PathBuf::from(cwd);