fix: runtime rules without conditionals

This commit is contained in:
iff 2024-11-15 21:17:11 +01:00
parent 86946a8fec
commit b3f963738b
2 changed files with 12 additions and 8 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "pay-respects"
version = "0.5.0"
version = "0.5.1"
edition = "2021"
# for crates.io

View file

@ -23,6 +23,7 @@ pub fn runtime_match(
let rule_dir = format!("{}/pay-respects/rules", xdg_config_home);
let file = format!("{}/{}.toml", rule_dir, executable);
if !std::path::Path::new(&file).exists() {
return None;
}
@ -31,6 +32,8 @@ pub fn runtime_match(
let rule: Rule = toml::from_str(&file).unwrap();
let split_command = split_command(&last_command);
let mut pure_suggest;
for match_err in rule.match_err {
for pattern in match_err.pattern {
if error_msg.contains(&pattern) {
@ -75,14 +78,15 @@ pub fn runtime_match(
}
}
pure_suggest = lines.join("\n").to_owned();
} else {
pure_suggest = suggest.to_owned();
}
// replacing placeholders
let mut suggest = lines.join("\n").to_owned();
if suggest.contains("{{command}}") {
suggest = suggest.replace("{{command}}", last_command);
}
eval_suggest(&suggest, last_command, error_msg, shell, &split_command);
return Some(suggest);
if pure_suggest.contains("{{command}}") {
pure_suggest = pure_suggest.replace("{{command}}", last_command);
}
return eval_suggest(&pure_suggest, last_command, error_msg, shell, &split_command);
}
}
}