diff --git a/module-runtime-rules/src/rules.rs b/module-runtime-rules/src/rules.rs index a891098..9590fd3 100644 --- a/module-runtime-rules/src/rules.rs +++ b/module-runtime-rules/src/rules.rs @@ -157,8 +157,8 @@ fn eval_suggest( if select_list.is_empty() { suggests.push(suggest); } else { - for exe in select_list { - let eval_suggest = suggest.clone().replace("{{selection}}", &exe); + for selection in select_list { + let eval_suggest = suggest.clone().replace("{{selection}}", &selection); suggests.push(eval_suggest); } } diff --git a/rules.md b/rules.md index 1edbe9b..86a736c 100644 --- a/rules.md +++ b/rules.md @@ -53,24 +53,34 @@ sudo {{command}} ''' The placeholder is evaluated as following: -- `{{command}}`: All the command without any modification. -- `{{command[1]}}`: The first argument of the command (the command itself has index of 0). Negative values will count from reverse. -- `{{command[2:5]}}`: The second to fifth arguments. If any of the side is not specified, then it defaults to the start (if it is left) or the end (if it is right). -- `{{typo[2](fix1, fix2)}}`: This will try to change the second argument to candidates in the parenthesis. The argument in parentheses must have at least 2 values. Single arguments are reserved for specific matches, for instance, `path` to search all commands found in the `$PATH` environment, or the `{{shell}}` placeholder, among others. -- `{{select[3][selection1, selection2]}}`: A derivative of `typo` placeholder. Will create a suggestion for each selection in the parenthesis. The argument in parentheses also must have at least 2 values. Single arguments are reserved for specific selections, for instance, `path` to search all commands found in the `$PATH` environment with the minimum linguistic distance, or the `{{shell}}` placeholder. - - Index is optional as it only has effect when using with `path`, and defaults to 0. -- `{{opt::}}`: Optional patterns captured in the command with RegEx ([see regex crate for syntax](https://docs.rs/regex-lite/latest/regex_lite/#syntax)). Note that all patterns matching this placeholder will be removed from indexing. -- `{{cmd::}}`: Get the matching captures from the last command. Unlike `{{opt}}`, this won't remove the string after matching -- `{{err::)}}`: Replace with the output of the shell command. This placeholder can be used along `{{typo}}` as its only argument, where each newline will be evaluated to a candidate. +- `{{command}}`: All the command without any modification +- `{{command[1]}}`: The first argument of the command (the command itself has index of 0) + - Negative values will count from reverse. +- `{{command[2:5]}}`: The second to fifth arguments + - If any of the side is not specified, then it defaults to the start (if it is left) or the end (if it is right) +- `{{typo[2](fix1, fix2)}}`: Try to change the second argument to candidates in the parenthesis. + - The argument in parentheses must have at least 2 values + - Single arguments are reserved for specific matches, for instance, `path` to search all commands found in the `$PATH` environment, or the `{{shell}}` placeholder, among others +- `{{select[3](selection1, selection2)}}`: A derivative of `typo` placeholder. Will create a suggestion for each selection in the parenthesis + - The argument in parentheses also must have at least 2 values + - Single arguments are reserved for specific selections, for instance, `path` to search all commands found in the `$PATH` environment with the minimum shared linguistic distance, or the `{{shell}}` placeholder + - To avoid permutations and combinations, only one instance is evaluated. If you need to apply the same selection in multiple places, use `{{selection}}` + - Index is optional as it only has effect when using with `path`, and defaults to `0` +- `{{opt::}}`: Optional patterns captured in the command with RegEx ([see regex crate for syntax](https://docs.rs/regex-lite/latest/regex_lite/#syntax)) + - All patterns matching this placeholder will be removed from indexing +- `{{cmd::}}`: Get the matching captures from the last command + - Unlike `{{opt}}`, this won't remove the string after matching +- `{{err::)}}`: Replace with the output of the shell command + - Can be used along `{{typo}}` or `{{select}}` as its only argument, where each newline will be evaluated to a candidate/selection 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. -- `shell`: Check if the current running shell is the argument. +- `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 +- `shell`: Check if the current running shell is the argument