Colocate more of bash parsing (#6489)

Move a few callsites that were detecting `bash -lc` into a shared
helper.
This commit is contained in:
pakrym-oai
2025-11-10 18:38:36 -08:00
committed by GitHub
parent 6c36318bd8
commit bb7b0213a8
3 changed files with 57 additions and 29 deletions

View File

@@ -1,6 +1,7 @@
use std::path::Path;
use std::path::PathBuf;
use codex_core::bash::extract_bash_command;
use dirs::home_dir;
use shlex::try_join;
@@ -8,19 +9,11 @@ pub(crate) fn escape_command(command: &[String]) -> String {
try_join(command.iter().map(String::as_str)).unwrap_or_else(|_| command.join(" "))
}
fn is_login_shell_with_lc(shell: &str) -> bool {
let shell_name = std::path::Path::new(shell)
.file_name()
.and_then(|s| s.to_str())
.unwrap_or(shell);
matches!(shell_name, "bash" | "zsh")
}
pub(crate) fn strip_bash_lc_and_escape(command: &[String]) -> String {
match command {
[first, second, third] if is_login_shell_with_lc(first) && second == "-lc" => third.clone(),
_ => escape_command(command),
if let Some((_, script)) = extract_bash_command(command) {
return script.to_string();
}
escape_command(command)
}
/// If `path` is absolute and inside $HOME, return the part *after* the home