pay-respects/README.md

103 lines
3.5 KiB
Markdown
Raw Normal View History

2023-07-31 21:38:04 +02:00
# Pay Respects
2023-07-30 18:40:18 +02:00
2023-07-31 21:38:04 +02:00
Typed a wrong command? Pay Respects will try to correct your wrong console command simply by pressing `F`!
2023-07-30 18:40:18 +02:00
2023-07-31 19:25:19 +02:00
![example-sudo-echo](img/example-sudo-echo.png)
![example-typo-paru](img/example-typo-paru.png)
![example-typo-git](img/example-typo-git.png)
2023-07-31 21:38:04 +02:00
## How to Pay Respects
2023-07-30 18:40:18 +02:00
2023-07-31 21:38:04 +02:00
The binary is named `pay-respects`, by adding an alias to your shell
2023-07-30 18:40:18 +02:00
configuration:
``` shell
2023-07-30 22:10:55 +02:00
# Note: You may need to have the binary exposed in your path
2023-07-31 21:38:04 +02:00
alias f="$(pay_respects <your_shell_here>)"
2023-07-31 14:22:20 +02:00
# for example, using `zsh`:
2023-07-31 21:38:04 +02:00
alias f="$(pay_respects zsh)"
2023-07-31 21:12:57 +02:00
# for `nushell`, the alias can be added automatically with:
2023-07-31 21:38:04 +02:00
pay_respects nushell
2023-07-30 18:40:18 +02:00
```
2023-07-31 21:38:04 +02:00
You can now **press `F` to Pay Respects**!
2023-07-30 18:40:18 +02:00
2023-07-31 15:06:30 +02:00
Currently, only corrections to `bash`, `zsh`, and `fish` are working flawlessly.
`nushell` has broken aliases, therefore it has following 2 limitations:
2023-07-31 21:38:04 +02:00
- You have to manually add the output of `pay_respects nushell` to your configuration as alias
2023-07-31 15:06:30 +02:00
- Aliased commands cannot be expanded to their original command
2023-07-30 22:10:55 +02:00
## Installing
If you are using Arch Linux, you can install from AUR directly:
```shell
2023-07-31 21:38:04 +02:00
paru -S pay_respects
2023-07-30 22:10:55 +02:00
```
2023-08-02 02:07:41 +02:00
Alternatively, you can download Linux binary from [releases](https://github.com/iffse/pay_respects/releases).
2023-07-30 22:10:55 +02:00
Otherwise, you can use cargo to compile the project:
```
cargo build --release
```
2023-07-31 21:38:04 +02:00
and the binary can be found at `target/release/pay_respects`.
2023-07-30 22:10:55 +02:00
2023-07-30 20:08:28 +02:00
## Rule Files
2023-08-03 21:27:52 +02:00
Rule files are parsed at compilation. Everything in rule files is converted to Rust code before compiling.
2023-07-30 20:08:28 +02:00
Syntax of a rule file (placed under [rules](./rules)):
```toml
# this field should be the name of the command
command = "world"
# you can add as many `[[match_err]]` section as you want
[[match_err]]
# the suggestion of this section will be used for the following patterns of the error output
# note that the error is formatted to lowercase without extra spaces
2023-07-30 20:08:28 +02:00
pattern = [
"pattern 1",
"pattern 2",
]
2023-07-30 20:22:49 +02:00
# this will change the first argument to `fix`, while keeping the rest intact
2023-08-02 03:05:25 +02:00
suggest = { "{{command[0]}} fix {{command[2:]}}" }
2023-07-30 20:08:28 +02:00
[[match_err]]
2023-07-30 20:08:28 +02:00
pattern = [
"pattern 1",
]
2023-07-31 10:20:06 +02:00
# this will add a `sudo` before the command if:
# - the `sudo` is found by `which`
2023-07-31 10:26:31 +02:00
# - the last command does not contain `sudo`
2023-08-02 03:05:25 +02:00
suggest = [
'''
2023-07-31 10:20:06 +02:00
#[executable(sudo), !cmd_contains(sudo)]
2023-07-31 09:24:46 +02:00
sudo {{command}}'''
2023-08-02 03:05:25 +02:00
]
2023-07-30 20:08:28 +02:00
```
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)
- `{{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).
2023-07-31 19:04:02 +02:00
- `{{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.
2023-08-01 19:35:22 +02:00
- `{{opt::<Regular Expression>}}`: Optional patterns that are found in the command with RegEx (see RegEx crate for syntax). Note that all patterns matching this placeholder will not take a place when indexing.
2023-07-30 20:08:28 +02:00
2023-07-31 10:20:06 +02:00
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
2023-07-30 18:40:18 +02:00
## Current Progress
2023-07-30 20:22:49 +02:00
We need more rule files!
2023-07-30 18:40:18 +02:00