feat: allow shell to execute command (useful for cd)

This commit is contained in:
iff 2023-08-12 22:55:31 +02:00
parent e63d55110e
commit cb38df3c37
3 changed files with 22 additions and 4 deletions

View file

@ -226,6 +226,7 @@ pub fn confirm_suggestion(shell: &str, command: &str, highlighted: &str) -> Resu
.unwrap();
if process.success() {
println!("{}", shell_evaluated_commands(&command));
return Ok(());
} else {
if now.elapsed() > Duration::from_secs(3) {
@ -257,6 +258,7 @@ pub fn confirm_suggestion(shell: &str, command: &str, highlighted: &str) -> Resu
.unwrap();
if process.success() {
println!("{}", shell_evaluated_commands(&command));
Ok(())
} else {
if now.elapsed() > Duration::from_secs(3) {
@ -272,3 +274,18 @@ pub fn confirm_suggestion(shell: &str, command: &str, highlighted: &str) -> Resu
Err(error_msg.to_string())
}
}
fn shell_evaluated_commands(command: &str) -> String {
let lines = command
.lines()
.map(|line| line.trim().trim_end_matches(['\\', ';', '|', '&']))
.collect::<Vec<&str>>();
let mut commands = Vec::new();
for line in lines {
if line.starts_with("cd") {
commands.push(line.to_string());
}
}
commands.join(" && ")
}