mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-11 22:10:09 +01:00
feat: exe_contains condition
This commit is contained in:
parent
d81ee69611
commit
5b690ed7ca
6 changed files with 15 additions and 8 deletions
|
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- `exe_contains` condition to check if the command contains the argument
|
||||
|
||||
### Fixed
|
||||
|
||||
- Parsing command environment variables (e.g. `LANG=ja_JP.UTF-8 pacman` will work as intended)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ pub fn match_pattern(executable: &str, data: &Data) -> Option<Vec<String>> {
|
|||
let last_command = &data.command;
|
||||
let executables = &data.executables;
|
||||
let mut candidates = vec![];
|
||||
let split = split_command(last_command);
|
||||
parse_rules!("rules");
|
||||
if candidates.is_empty() {
|
||||
None
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ fn eval_condition(
|
|||
"executable" => executables.contains(&arg.to_string()),
|
||||
"err_contains" => error_msg.contains(arg),
|
||||
"cmd_contains" => last_command.contains(arg),
|
||||
"exe_contains" => split_command[0].contains(arg),
|
||||
"min_length" => split_command.len() >= arg.parse::<usize>().unwrap(),
|
||||
"length" => split_command.len() == arg.parse::<usize>().unwrap(),
|
||||
"max_length" => split_command.len() <= arg.parse::<usize>().unwrap() + 1,
|
||||
|
|
|
|||
|
|
@ -104,7 +104,6 @@ fn gen_match_rules(rules: &[Rule]) -> TokenStream {
|
|||
#(
|
||||
for pattern in #patterns_tokens {
|
||||
if error_msg.contains(pattern) {
|
||||
let split = split_command(&last_command);
|
||||
#suggestion_tokens;
|
||||
};
|
||||
})*
|
||||
|
|
@ -173,6 +172,7 @@ fn eval_condition(condition: &str, arg: &str) -> TokenStream2 {
|
|||
"executable" => quote! {executables.contains(&#arg.to_string())},
|
||||
"err_contains" => quote! {error_msg.contains(#arg)},
|
||||
"cmd_contains" => quote! {last_command.contains(#arg)},
|
||||
"exe_contains" => quote! {split[0].contains(#arg)},
|
||||
"min_length" => quote! {(split.len() >= #arg.parse::<usize>().unwrap())},
|
||||
"length" => quote! {(split.len() == #arg.parse::<usize>().unwrap())},
|
||||
"max_length" => quote! {(split.len() <= #arg.parse::<usize>().unwrap() + 1)},
|
||||
|
|
|
|||
13
rules.md
13
rules.md
|
|
@ -76,11 +76,12 @@ The placeholder is evaluated as following:
|
|||
|
||||
Suggestions can have additional conditions to check. To specify conditions, add a `#[...]` at the first line (just like derive macros in Rust). Available conditions:
|
||||
|
||||
- `executable`: Check whether the argument can be found in path
|
||||
- `cmd_contains`: Check whether the last user input contains the argument
|
||||
- `err_contains`: Check whether the error of the command contains the argument
|
||||
- `length`: Check whether the given command has the length of the argument
|
||||
- `min_length`: Check whether the given command has at least the length of the argument
|
||||
- `max_length`: Check whether the given command has at most the length of the argument
|
||||
- `executable`: Check if the argument can be found in path
|
||||
- `cmd_contains`: Check if the last user input contains the argument
|
||||
- `err_contains`: Check if the error of the command contains the argument
|
||||
- `exe_contains`: Check if the command name itself contains the argument
|
||||
- `length`: Check if the given command has the length of the argument
|
||||
- `min_length`: Check if the given command has at least the length of the argument
|
||||
- `max_length`: Check if the given command has at most the length of the argument
|
||||
- `shell`: Check if the current running shell is the argument
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ pattern = [
|
|||
]
|
||||
suggest = [
|
||||
'''
|
||||
#[cmd_contains(./)]
|
||||
#[exe_contains(/)]
|
||||
chmod +x {{command[0]}} &&
|
||||
{{command}}'''
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue