feat: auto adapt suggestion to shell syntax

This commit is contained in:
iff 2024-11-18 13:11:13 +01:00
parent 171b3d4607
commit 8f9aac6bdc
3 changed files with 47 additions and 20 deletions

View file

@ -246,3 +246,37 @@ end
std::process::exit(0);
}
pub fn shell_syntax(shell: &str, command: &mut String) {
#[allow(clippy::single_match)]
match shell {
"nushell" => {
*command = command.replace(" && ", " and ");
}
_ => {}
}
}
pub fn shell_evaluated_commands(shell: &str, command: &str) -> Option<String> {
let lines = command
.lines()
.map(|line| line.trim().trim_end_matches(['\\', ';', '|', '&']))
.collect::<Vec<&str>>();
let mut dirs = Vec::new();
for line in lines {
if let Some(dir) = line.strip_prefix("cd ") {
dirs.push(dir.to_string());
}
}
let cd_dir = dirs.join("");
if cd_dir.is_empty() {
return None;
}
#[allow(clippy::single_match)]
match shell {
"nushell" => Some(cd_dir),
_ => Some(format!("cd {}", cd_dir)),
}
}