Skip to content
Projetos

iffse/pay-respects

Ver no GitHub

Sobre

Sugestões de comandos e substituto para command-not-found e thefuck, escrito em Rust.

Ferramentas de desenvolvimento

Como estes números são medidos

Crescimento medido de estrelas

em 24 h
+1
em 7 dias
+2
em 15 dias
+4
em 1 mês
+8

Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.

README.md

Original

Pay Respects

Your command failed. Press F for it and get back to work!

  • 🚀 Performant: Sub-millisecond (<1ms) performance! See the benchmarks.
  • 🎯 Accurate: No blind guesses. Suggestions are checked first!
  • ✏️ Rules in TOML: Write fixes without touching Rust!
  • 🔩 Extendable: Go full Rust, use interpreted scripts, or build a module when TOML is not enough!
  • 🤖 Optional AI: No rule? Let AI take a shot!
  • 🪶 Small binary: Under 1 MB for core features!

showcase

How to Pay Respects

Pick your shell:

Bash / Zsh / Fish / Dash

Add the matching line to your shell configuration file:

eval "$(pay-respects bash --alias)"
eval "$(pay-respects zsh --alias)"
pay-respects fish --alias | source
eval "$(pay-respects dash --alias)"

Arguments:

  • --alias [alias]: Command name, defaults to f
  • --shell-type <type>: Shell type when the binary name differs
  • --nocnf: Disable the command_not_found handler

The shell binary name is detected automatically. Use --shell-type for forks such as pay-respects zsh-fork --shell-type zsh.

Dash has no inline mode or command-not-found handler.

Xonsh

Add this line to ~/.xonshrc:

execx($(pay-respects xonsh --alias), 'exec', __xonsh__.ctx, filename='pay-respects')

Ctrl-X Ctrl-X runs inline mode when prompt_toolkit is available.

Elvish

Add this line to ~/.config/elvish/rc.elv:

eval (pay-respects elvish --alias | slurp)

Type f to suggest a fix. Ctrl-X runs inline mode. Elvish has no command-not-found handler.

Nushell

Add the generated lines to your Nushell config:

# replace `nu` with `nush` or `nushell` if your binary has a different name
pay-respects nu --alias [<alias>]

Or save them to a file and source it:

pay-respects nu --alias [<alias>] | save -f ~/.pay-respects.nu

source ~/.pay-respects.nu
PowerShell

Add the generated lines to your profile:

# replace `pwsh` with `powershell` if your binary has a different name
pay-respects pwsh --alias [<alias>]

Or append them directly:

pay-respects pwsh --alias [<alias>] >> $PROFILE
Custom initialization for any shell

pay-respects needs two environment variables:

  • _PR_SHELL: Binary name of the current shell
  • _PR_LAST_COMMAND: Last command

pay-respects prints commands that the shell should evaluate, such as cd.

Example:

eval $(_PR_SHELL=zsh-fork _PR_SHELL_TYPE=zsh _PR_LAST_COMMAND="git comit" pay-respects)

These variables are optional. They let pay-respects skip work:

  • _PR_SHELL_TYPE: Shell type. Auto-detected from _PR_SHELL if absent.
  • _PR_ALIAS: Aliases to commands, separated by newlines in zsh format, for example gc=git commit
  • _PR_ERROR_MSG: Error message from the previous command. If absent, pay-respects reads it from a multiplexer log or reruns the command.
  • _PR_EXECUTABLES: Space-separated list of executables. If absent, pay-respects scans $PATH.
  • _PR_LOG: Debug builds only. Write debug logs to stderr or a file path. 1 writes pay-respects.log in the current directory. Unset disables logs.
  • _PR_LOG_LEVEL: Maximum debug log level, default 5.

Press F to pay respects.

Ctrl+X Ctrl+X runs experimental inline mode. It fixes the command in place without executing it:

  • gitcommit + C-X C-X → git commit
  • z payrespe + C-X C-X → cd /home/iff/Code/pay-respects

In fish and Nushell, pressing e in the suggestion list puts the selected fix back into the prompt instead of running it. Edit it with the shell's own key bindings and press Enter when ready:

  • gitcommit + f + e → git commit at the prompt

On other shells, or with [ui] prompt_edit = false, e opens the selected fix in $VISUAL/$EDITOR and runs it when saved.

Integrations with other tools
  • tmux, GNU Screen, Zellij, WezTerm, kitty:
    • Read the command log from the session. This avoids rerunning the command to get its error message. Set LANG=C so the log matches reliably.
    • The prompt must show a prefix before the command. The generated shell config sets this up.
  • zoxide: Uses its database to navigate directories.
Environment variable configuration
  • _PR_LIB: Module directories, separated like PATH. If unset, pay-respects uses PATH and the compile-time value.
  • _PR_PACKAGE_MANAGER: Package manager to use instead of guessing from an alphabetical list. Set it to an empty value to disable package search.
    • _DEF_PR_PACKAGE_MANAGER: Compile-time value

_PR_MODE selects the run mode:

  • noconfirm: Execute a suggestion without confirmation
  • inline: Print the best fix without executing it
  • echo: Print suggestions to stdout without executing them
  • cnf: Internal mode for the command-not-found hook

Example with noconfirm:

# new versions
alias ff="__pr_main noconfirm"

# old versions
function ff() {
	(
		export _PR_MODE="noconfirm"
		f
	)
}

Other options:

  • _PR_NO_CONFIG: Skip configuration files
  • _PR_NO_DESPERATE: Disable slow fallback checks that sometimes give a better result
  • _PR_PREFIX: Prompt prefix before the command. Needed to read logs from multiplexers.
  • Disable integrations:
    • _PR_NO_ZOXIDE
    • _PR_NO_MULTIPLEXER: Same as setting all of these:
      • _PR_NO_TMUX
      • _PR_NO_SCREEN
      • _PR_NO_ZELLIJ
      • _PR_NO_WEZTERM
      • _PR_NO_KITTY

Installing

Install from your package manager if available:

Packaging status

Instructions for package managers
OS / Distribution Repository Instructions
Arch Linux AUR paru -S pay-respects (-bin)
Arch Linux (ARM) Arch Linux CN sudo pacman -S pay-respects
MacOS / Any timescam brew install timescam/homebrew-tap/pay-respects
NixOS / Any nixpkgs nix-env -iA nixos.pay-respects

Pre-built binaries are on GitHub releases. Install scripts are also available. On Unix:

curl -sSfL https://raw.githubusercontent.com/iffse/pay-respects/main/install.sh | sh

On Windows, with PowerShell:

irm https://raw.githubusercontent.com/iffse/pay-respects/main/install.ps1 | iex
Cargo / Compile from source (any OS and architecture supported by Rust)

You need Cargo for this.

Install the core package and any modules you want from crates.io:

cargo install pay-respects
cargo install pay-respects-module-runtime-rules
cargo install pay-respects-module-request-ai

A git clone is better if you want custom compile-time rules:

git clone --depth 1 https://github.com/iffse/pay-respects
cd pay-respects
cargo install --path core
cargo install --path module-runtime-rules
cargo install --path module-request-ai

Configuration

See configuration.

Rules & Modules

AI Integration

Disclaimer: AI suggestions can be wrong. Check them before you accept one.

AI suggestions are opt-in. When request-ai is installed and no API key is configured, the module asks whether to use the built-in key. You can remember the answer in the configuration file:

[module.request-ai]
enabled = true

Set enabled = false, or set _PR_AI_DISABLE to any value, to turn AI suggestions off:

export _PR_AI_DISABLE=1

A built-in API key ships with the source. Some distributions remove it. The service is free while I can cover the cost. It may stop when rate limits hit.

The proxy does not track or store anything. If the service is useful to you, consider a donation:

Donate using Liberapay Donate using Ko-fi
Donate using Stripe Donate using PayPal

AI usage and API configuration

Contributing

The current rule format covers most cases. More rules are welcome.

See the roadmap for open work.

The project is mirrored on several sites. Pick the one you prefer:

Licenses

  • Binaries: AGPL-3.0
    • Core and modules
  • Libraries: MPL-2.0
    • Parser, rule engine, utils, and select

Benchmarks

Run make bench with hyperfine to reproduce these numbers. The results below come from my machine (AMD Ryzen 5 5600X, DDR4 2400 MHz, HDD 7200 RPM with Btrfs compression, glibc build). Yours will differ.

Case Results
Initialization 493.7 µs ± 38.1 µs
Privilege 655.0 µs ± 100.4 µs
Typo: Command 5.1 ms ± 0.2 ms
Typo: File path 3.6 ms ± 0.4 ms
RegEx: Command 3.3 ms ± 0.1 ms
RegEx: Options 3.3 ms ± 0.2 ms
RegEx: Error 3.3 ms ± 0.1 ms
Desperate: Fuzzy recovery 703.5 µs ± 65.9 µs
Desperate: File look up 3.4 ms ± 0.2 ms

Caveats:

  • Integrations are off: In real use, a delay can come from a tool such as zoxide. It takes about 50 ms on its own.
  • Binaries are optimized for size, not speed. They use regex-lite instead of regex because it is smaller, though slower. A smaller binary loads faster, especially on a cold run.

Flowchart

How it works:

flowchart

Explore projetos relacionados

Carregando…