Terminal command correction, alternative to thefuck written in Rust

Overview

Pay Respects

Typed a wrong command? Pay Respects will try to correct your wrong console command by simply pressing F!

  • 🚀 Blazing fast suggestion: You won't notice any delay for asking suggestions!
  • ✏️ Easy to write rules: You don't need to know Rust. The rules are written in a TOML file that is simple to work with and evaluated to Rust code upon compilation!
  • 🪶 Tiny binary size: Not even 1MB!

example-sudo-echo-write

example-typo-paru

example-typo-git

How to Pay Respects

The binary is named pay-respects, by adding an alias to your shell configuration:

# Note: You may need to have the binary exposed in your path
alias f="$(pay-respects <your_shell_here>)"

# for example, using `zsh`:
alias f="$(pay-respects zsh)"

# Alternatively, you can also use the following initialization in your config file
# for bash and zsh
eval "$(pay-respects <shell> --alias)"
# for fish
pay-respects fish --alias | source

# for `nushell`, the alias can be added automatically with:
pay-respects nushell

You can now press F to Pay Respects!

Currently, only corrections to bash, zsh, and fish are working flawlessly.

nushell has broken aliases, therefore it has following 2 limitations:

  • You have to manually add the output of pay-respects nushell to your configuration as alias
  • Aliased commands cannot be expanded to their original command

Installing

If you are using Arch Linux, you can install from AUR directly:

paru -S pay-respects

Alternatively, you can download Linux binary from releases.

Otherwise, you can use cargo to compile the project:

cargo build --release

and the binary can be found at target/release/pay-respects.

Rule Files

Rule files are parsed at compilation. Everything in rule files is converted to Rust code before compiling. You don't have to know the project structure nor Rust to write the rules!

Syntax of a rule file (will be read by simply placing the file under rules):

# 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
pattern = [
	"pattern 1",
	"pattern 2"
]
# this will change the first argument to `fix`, while keeping the rest intact
suggest = [
	"{{command[0]}} fix {{command[2:]}}",
]

[[match_err]]
pattern = [
	"pattern 1",
]
# this will add a `sudo` before the command if:
# - the `sudo` is found by `which`
# - the last command does not contain `sudo`
suggest = [
'''
#[executable(sudo), !cmd_contains(sudo)]
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)
  • {{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).
  • {{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.
  • {{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.
  • {{cmd::<Regular Expression>}}: Get the matching pattern from the last command. Unlike {{opt}}, this won't remove the string after matching
  • {{err::<Regular Expression}}: Get the matching patterns from the error message.
  • {{shell(<shell commands>)}}: 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.

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

Current option to write rules should cover most of the cases.

We need more rule files, contributions are welcomed!

You might also like...
Generate, display and solve mazes in an animated way in the terminal.
Generate, display and solve mazes in an animated way in the terminal.

How to Run Usage: maze_solver.exe [OPTIONS] --generator GENERATOR|--input INPUT [ROWS] [COLUMNS] Arguments: [ROWS] Number of rows to draw

Ktx is a lightweight terminal-ui utility for editing Kubernetes config
Ktx is a lightweight terminal-ui utility for editing Kubernetes config

ktx Ktx is a lightweight terminal-ui utility for editing the kubectl config If you work with a large infrastructure where you have to jump between clu

Generate rust command line executables from gRPC protobuf services.

Rust template repository. An opinionated starting point for rust projects such as systemd services command line tools client programs server programs

Rust-based command-line language-learning game. Uses the Tatoeba database.

minicloze A command-line language learning game using Tatoeba's great database. Accelerate your studies by putting your knowledge to the test in an ad

The official command-line interface for the makedeb Package Repository

Mist This is the repository for Mist, the official helper for the makedeb Package Repository. Installation Users have a few options for installing Mis

UEFI command-line tool for read/write access of variables

UEFI Command Line Tool for Reading/Writing UEFI Variables This tool is a rewritten version of the modded grub with setup_var commands, enhanced with m

A no-frills Tetris implementation written in Rust with the Piston game engine, and Rodio for music.
A no-frills Tetris implementation written in Rust with the Piston game engine, and Rodio for music.

rustris A no-frills Tetris implementation written in Rust with the Piston game engine, and Rodio for music. (C) 2020 Ben Cantrick. This code is distri

A tool to generate inbetweens for animated sprites, written in godot-rust
A tool to generate inbetweens for animated sprites, written in godot-rust

Bitmapflow is a tool to help you generate inbetweens for animated sprites. In other words, it makes your animations smoother. It uses optical flow to

Text Renderer written in Rust using HarfBuzz for shaping, FreeType for rasterization and OpenGL for rendering.
Text Renderer written in Rust using HarfBuzz for shaping, FreeType for rasterization and OpenGL for rendering.

Provok Text Renderer written in Rust using HarfBuzz for shaping, FreeType for rasterization and OpenGL for rendering. Input Provok is fed with a JSON

Comments
  • [Bug]: Not passing some environment variables when calls the corrected command

    [Bug]: Not passing some environment variables when calls the corrected command

    What happened?

    I am using ArchLinux with zh_CN.UTF-8 locale, however, when this program runs corrected command, environment variables such as LANG are not passed to the corrected command.

    The command and output

    Note: this log contains non-English words:

    # zhanghua @ archlinux in ~ [12:38:59]
    $ pacman -S
    错误:非 root (根用户) 无法执行指定操作。
    # zhanghua @ archlinux in ~ [12:39:02] C:1 
    $ f
    sudo pacman -S
    
    Press enter to execute the suggestion. Or press Ctrl+C to exit.
    
    [sudo] password for zhanghua: 
    error: no targets specified (use -h for help)
    
    # zhanghua @ archlinux in ~ [12:39:10]
    $ 
    
    

    The sudo command called by pay-respects seems that it does not have the proper LANG environment variable so its outputs becomes English

    No similar issue

    • [X] I have searched the issue list and there is no similar issue found
    bug 
    opened by zhanghua000 1
  • doc: Add issue template and dependabot

    doc: Add issue template and dependabot

    Using dependabot for updating depends(rust and github actions) Adding issue template for better user experience As most changes are not related to actual code, adding [skip ci] in almost all commits(I forgot to add for some of the commits)

    opened by zhanghua000 0
rpg-cli is a bare-bones JRPG-inspired terminal game written in Rust

rpg-cli is a bare-bones JRPG-inspired terminal game written in Rust. It can work as an alternative to cd where you randomly encounter enemies as you change directories.

Facundo Olano 660 May 27, 2021
Terminal-based Snake game written in Rust without dependencies (for educational purposes).

RustSnake This is a simple terminal-based Snake game implemented in Rust without dependencies. To start the game type cargo run. Control the snake usi

Florian Wickert 88 Jan 6, 2023
A simple space shooter game. Runs in the terminal using characters-based UI. Fully written in Rust, using the "ruscii" library.

Thrust - a terminal shooter game Originally created as a project for the "Missing Semester" course at JKU Linz (338.006). The game is entirely written

Mathias Wöß 3 Jan 16, 2023
A terminal battleship game in Rust

Battleship.rs A terminal battleship game in Rust. Run with docker: $ docker run --rm -it deepu105/battleship:main This is slightly different than the

Deepu K Sasidharan 56 Dec 19, 2022
Terminal typing "game"

ToggleCoolCowSaysType A terminal based typing game. Usage: toggle_cool_cow_says_type [-t {word_count}] [-t {file_extension}] [-s] {project_path} -s :

Togglebit 23 Sep 27, 2022
Terminal UI implementation and types for the Dark Forest game

dark-forest.rs Terminal UI implementation and types for the Dark Forest game Development We use the standard Rust toolchain cargo check

Georgios Konstantopoulos 63 Nov 12, 2022
A terminal based game engine

ccdb: The cmd game engine (Thats also multi threaded) How to use Tutorial Multi threading If you want to use multi threading you have to use ACore The

null 34 Oct 19, 2022
Play jungle chess on the linux terminal.

Jungle-Chess This is my first project written in Rust. Happy for contributors and feedback! The code is dirty. Play Jungle Chess on an Emoji-Enabled L

Arne Winter 10 Aug 9, 2022
Play or watch Othello in your terminal!

othello-cli othello-cli is a cli version of Othello (Reversi) written in Rust. You can play against another player, the AI, or watch two AIs play each

null 4 Oct 18, 2022
Transform your terminal into an art canvas where you can draw stuff!

Termdraw Turn your terminal into the drawing cavnas of your dream... or not! Installation To install this dream-come-true of a tool simply run cargo i

Enoki 5 Nov 23, 2022