feat: more conditionals

This commit is contained in:
iff 2023-07-31 10:20:06 +02:00
parent 6b4d926dde
commit 9ebe08ad64
4 changed files with 56 additions and 30 deletions

View file

@ -48,9 +48,12 @@ suggest = "{{command[0]}} fix {{command[2:]}}"
pattern = [
"pattern 1",
]
# this will add a `sudo` before the command if the `sudo` is found by `which`
# this will add a `sudo` before the command if:
# - the `sudo` is found by `which`
# - the command last command does not contain `sudo`
# - the last command typed by the user does not contain `sudo`
suggest = '''
#[executable(sudo)]
#[executable(sudo), !cmd_contains(sudo)]
sudo {{command}}'''
```
@ -60,6 +63,12 @@ The placeholder is evaluated as following:
- `{{command[1]}}`: The first argument of the command (the command itself has index of 0)
- `{{command[2:5]}}`: The second to fifth arguments. If any of the side is not specified, them it defaults to the start (if it is left) or the end (if it is right).
The suggestion can have additional conditions to check. To specify the conditions, add a `#[...]` at the first line (just like derive macros in Rust). Available conditions:
- `executable`: Check if the argument can be found by `which`
- `cmd_contains`: Check if the last user input contains the argument
- `err_contains`: Check if the error of the command contains the argument
## Current Progress
We need more rule files!