mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-12 14:30:10 +01:00
feat: allow shell to execute command (useful for cd)
This commit is contained in:
parent
e63d55110e
commit
cb38df3c37
3 changed files with 22 additions and 4 deletions
|
|
@ -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(" && ")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue