chore: don't run merge multiple times

This commit is contained in:
iff 2025-04-10 17:08:16 +02:00
parent fea920ac7a
commit 0f5f3b70e7
2 changed files with 10 additions and 3 deletions

View file

@ -650,13 +650,13 @@ pub fn shell_syntax(shell: &str, command: &str) -> String {
} }
} }
pub fn shell_evaluated_commands(shell: &str, command: &str, cd: bool) { pub fn shell_evaluated_commands(shell: &str, command: &str, success: bool) {
let lines = command let lines = command
.lines() .lines()
.map(|line| line.trim().trim_end_matches(['\\', ';', '|', '&'])) .map(|line| line.trim().trim_end_matches(['\\', ';', '|', '&']))
.collect::<Vec<&str>>(); .collect::<Vec<&str>>();
let cd = if cd { let cd = if success {
let dirs = { let dirs = {
let mut dirs = Vec::new(); let mut dirs = Vec::new();
for line in lines { for line in lines {
@ -692,6 +692,7 @@ pub fn shell_evaluated_commands(shell: &str, command: &str, cd: bool) {
struct FishTemplate<'a> { struct FishTemplate<'a> {
command: &'a str, command: &'a str,
cd: Option<&'a str>, cd: Option<&'a str>,
success: bool,
} }
#[derive(Template)] #[derive(Template)]
#[template(path = "eval.nu", escape = "none")] #[template(path = "eval.nu", escape = "none")]
@ -729,6 +730,7 @@ pub fn shell_evaluated_commands(shell: &str, command: &str, cd: bool) {
let template = FishTemplate { let template = FishTemplate {
command: &command, command: &command,
cd: cd.as_deref(), cd: cd.as_deref(),
success,
}; };
template.render().unwrap() template.render().unwrap()
} }
@ -741,5 +743,8 @@ pub fn shell_evaluated_commands(shell: &str, command: &str, cd: bool) {
template.render().unwrap() template.render().unwrap()
} }
}; };
println!("{}", print.trim()); let print = print.trim();
if !print.is_empty() {
println!("{}", print);
}
} }

View file

@ -1,5 +1,7 @@
builtin history append "{{ command }}"; builtin history append "{{ command }}";
{%- if success %}
builtin history merge; builtin history merge;
{%- endif %}
{%- if let Some(cd) = self.cd %} {%- if let Some(cd) = self.cd %}
cd {{ cd }} cd {{ cd }}