mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-11 22:10:09 +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
|
|
@ -9,5 +9,6 @@ pattern = [
|
|||
suggest = [
|
||||
'''
|
||||
#[err_contains(no such file or directory)]
|
||||
mkdir -p {{command[1]}} '''
|
||||
mkdir -p {{command[1]}}
|
||||
cd {{command[1]}} '''
|
||||
]
|
||||
|
|
|
|||
|
|
@ -183,10 +183,10 @@ pub fn initialization(shell: &str, binary_path: &str, auto_alias: &str) {
|
|||
|
||||
let mut init = format!(
|
||||
"\
|
||||
_PR_LAST_COMMAND=\"{}\" \
|
||||
eval $(_PR_LAST_COMMAND=\"{}\" \
|
||||
_PR_ALIAS=\"{}\" \
|
||||
_PR_SHELL=\"{}\" \
|
||||
\"{}\"",
|
||||
\"{}\")",
|
||||
last_command, alias, shell, binary_path
|
||||
);
|
||||
|
||||
|
|
@ -197,7 +197,7 @@ pub fn initialization(shell: &str, binary_path: &str, auto_alias: &str) {
|
|||
|
||||
match shell {
|
||||
"bash" | "zsh" => {
|
||||
init = format!(r#"alias {}='{}'"#, auto_alias, init);
|
||||
init = format!(r#"alias {}=eval '$({})'"#, auto_alias, init);
|
||||
}
|
||||
"fish" => {
|
||||
init = format!(
|
||||
|
|
|
|||
|
|
@ -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