diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index c3f4d5db7..46e9ab5b1 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -1,6 +1,4 @@ use crate::hook::eval_hook; -use fancy_regex::Regex; -use itertools::Itertools; use nu_engine::env_to_strings; use nu_engine::CallExt; use nu_protocol::{ @@ -651,8 +649,6 @@ impl ExternalCommand { } else { self.spawn_simple_command(cwd) } - } else if self.name.item.ends_with(".sh") { - Ok(self.spawn_sh_command()) } else { self.spawn_simple_command(cwd) } @@ -698,19 +694,6 @@ impl ExternalCommand { process } - - /// Spawn a sh command with `sh -c args...` - pub fn spawn_sh_command(&self) -> std::process::Command { - let joined_and_escaped_arguments = self - .args - .iter() - .map(|arg| shell_arg_escape(&arg.item)) - .join(" "); - let cmd_with_args = vec![self.name.item.clone(), joined_and_escaped_arguments].join(" "); - let mut process = std::process::Command::new("sh"); - process.arg("-c").arg(cmd_with_args); - process - } } fn trim_expand_and_apply_arg( @@ -796,23 +779,6 @@ fn suggest_command(attempted_command: &str, engine_state: &EngineState) -> Optio } } -fn has_unsafe_shell_characters(arg: &str) -> bool { - let re: Regex = Regex::new(r"[^\w@%+=:,./-]").expect("regex to be valid"); - - re.is_match(arg).unwrap_or(false) -} - -fn shell_arg_escape(arg: &str) -> String { - match arg { - "" => String::from("''"), - s if !has_unsafe_shell_characters(s) => String::from(s), - _ => { - let single_quotes_escaped = arg.split('\'').join("'\"'\"'"); - format!("'{single_quotes_escaped}'") - } - } -} - /// This function returns a tuple with 3 items: /// 1st item: trimmed string. /// 2nd item: a boolean value indicate if it's ok to run glob expansion.