diff options
Diffstat (limited to 'src/modules/custom.rs')
-rw-r--r-- | src/modules/custom.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/modules/custom.rs b/src/modules/custom.rs index ee1e07389..d569190e8 100644 --- a/src/modules/custom.rs +++ b/src/modules/custom.rs @@ -5,7 +5,7 @@ use std::time::Instant; use super::{Context, Module, RootModuleConfig}; -use crate::{configs::custom::CustomConfig, formatter::StringFormatter}; +use crate::{configs::custom::CustomConfig, formatter::StringFormatter, utils::create_command}; /// Creates a custom module with some configuration /// @@ -100,7 +100,7 @@ fn get_shell<'a, 'b>(shell_args: &'b [&'a str]) -> (std::borrow::Cow<'a, str>, & #[cfg(not(windows))] fn shell_command(cmd: &str, shell_args: &[&str]) -> Option<Output> { let (shell, shell_args) = get_shell(shell_args); - let mut command = Command::new(shell.as_ref()); + let mut command = create_command(shell.as_ref()).ok()?; command .args(shell_args) @@ -118,6 +118,7 @@ fn shell_command(cmd: &str, shell_args: &[&str]) -> Option<Output> { "Could not launch command with given shell or STARSHIP_SHELL env variable, retrying with /usr/bin/env sh" ); + #[allow(clippy::disallowed_method)] Command::new("/usr/bin/env") .arg("sh") .stdin(Stdio::piped()) @@ -141,14 +142,17 @@ fn shell_command(cmd: &str, shell_args: &[&str]) -> Option<Output> { Some(std::borrow::Cow::Borrowed(shell_args[0])), &shell_args[1..], ) - } else if let Ok(env_shell) = std::env::var("STARSHIP_SHELL") { + } else if let Some(env_shell) = std::env::var("STARSHIP_SHELL") + .ok() + .filter(|s| !cfg!(test) && !s.is_empty()) + { (Some(std::borrow::Cow::Owned(env_shell)), &[] as &[&str]) } else { (None, &[] as &[&str]) }; if let Some(forced_shell) = shell { - let mut command = Command::new(forced_shell.as_ref()); + let mut command = create_command(forced_shell.as_ref()).ok()?; command .args(shell_args) @@ -169,7 +173,8 @@ fn shell_command(cmd: &str, shell_args: &[&str]) -> Option<Output> { ); } - let command = Command::new("cmd.exe") + let command = create_command("cmd") + .ok()? .arg("/C") .arg(cmd) .stdin(Stdio::piped()) |