fix: check executable in nushell

This commit is contained in:
iff 2023-08-08 16:57:14 +02:00
parent c2708a4de5
commit 6a06aa5954
3 changed files with 26 additions and 12 deletions

View file

@ -37,7 +37,7 @@ You can now **press `F` to Pay Respects**!
Currently, only corrections to `bash`, `zsh`, and `fish` are working flawlessly. Currently, only corrections to `bash`, `zsh`, and `fish` are working flawlessly.
Note that `nushell` support is currently very broken. `nushell` is currently usable, but there is no alias expansion and you will have to add the corresponding environment variables manually.
## Installing ## Installing

View file

@ -166,17 +166,7 @@ fn parse_conditions(suggest: &str) -> (String, Vec<TokenStream2>) {
fn eval_condition(condition: &str, arg: &str) -> TokenStream2 { fn eval_condition(condition: &str, arg: &str) -> TokenStream2 {
match condition { match condition {
"executable" => { "executable" => quote!{check_executable(shell, #arg)},
quote!{
std::process::Command::new(shell)
.arg("-c")
.arg(format!("command -v {}", #arg))
.output()
.expect("failed to execute process")
.status
.success()
}
},
"err_contains" => quote!{error_msg.contains(#arg)}, "err_contains" => quote!{error_msg.contains(#arg)},
"cmd_contains" => quote!{last_command.contains(#arg)}, "cmd_contains" => quote!{last_command.contains(#arg)},
_ => unreachable!("Unknown condition when evaluation condition: {}", condition), _ => unreachable!("Unknown condition when evaluation condition: {}", condition),

View file

@ -44,6 +44,30 @@ fn match_pattern(
parse_rules!("rules"); parse_rules!("rules");
} }
fn check_executable(shell: &str, executable: &str) -> bool {
match shell {
"nu" => {
std::process::Command::new(shell)
.arg("-c")
.arg(format!("if (which {} | is-empty) {{ exit 1 }}", executable))
.output()
.expect("failed to execute process")
.status
.success()
}
_ => {
std::process::Command::new(shell)
.arg("-c")
.arg(format!("command -v {}", executable))
.output()
.expect("failed to execute process")
.status
.success()
}
}
}
fn opt_regex(regex: &str, command: &mut String) -> String { fn opt_regex(regex: &str, command: &mut String) -> String {
let regex = Regex::new(regex).unwrap(); let regex = Regex::new(regex).unwrap();
let opts = regex let opts = regex