Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsMay 12, 2026·3 min de lectura

thefuck — Magnificent Command Corrector for Your Terminal

A CLI tool that corrects your previous console command by suggesting and running the right fix automatically.

Introduction

thefuck is a Python CLI app that listens for failed commands in your shell and proposes corrected alternatives. When you mistype a command, forget sudo, or use wrong flags, just type fuck and it will fix and re-run the command for you.

What thefuck Does

  • Detects failed shell commands based on exit codes and stderr output
  • Matches failures against a library of built-in correction rules
  • Suggests the most likely corrected command automatically
  • Supports custom user-defined rules for project-specific workflows
  • Works across Bash, Zsh, Fish, PowerShell, and tcsh

Architecture Overview

thefuck intercepts the previous command's exit code and output via a shell alias. It then passes that context through a pipeline of rule matchers, each of which checks whether it can fix the error. Rules are plain Python modules with match() and get_new_command() functions. The highest-priority matching rule produces the corrected command, which is presented to the user or executed immediately based on configuration.

Self-Hosting & Configuration

  • Install via pip: pip install thefuck or via Homebrew: brew install thefuck
  • Initialize the alias in your shell profile with eval $(thefuck --alias)
  • Configure settings in ~/.config/thefuck/settings.py (timeout, rules, priority)
  • Set require_confirmation = False to auto-execute corrections without prompting
  • Add custom rules as Python files in ~/.config/thefuck/rules/

Key Features

  • Ships with 80+ built-in rules covering git, docker, pip, apt, cargo, and more
  • Learns from your corrections and adjusts rule priority over time
  • Supports instant mode for near-zero latency corrections
  • Custom aliases let you rename the command to anything you prefer
  • Extensible rule system with a simple two-function Python interface

Comparison with Similar Tools

  • ShellCheck — static analysis for scripts; thefuck corrects interactive commands in real time
  • zsh-autosuggestions — suggests from history; thefuck actively fixes failed commands
  • fuck (Ruby) — earlier concept; thefuck has a much larger rule library and active maintenance
  • pay-respects — Rust alternative with faster startup but fewer built-in rules

FAQ

Q: Does thefuck slow down my shell? A: In normal mode the alias only activates when you explicitly type the trigger. Instant mode adds a small hook but is designed to stay under 100ms.

Q: Can I use a different trigger word? A: Yes. Pass a custom name to the alias: eval $(thefuck --alias fix) and then type fix instead.

Q: Does it work with zsh and oh-my-zsh? A: Yes. There is also a bundled oh-my-zsh plugin for convenience.

Q: Is it safe to auto-run corrections? A: By default it asks for confirmation. You can enable auto-run, but review the rule list first to avoid surprises with destructive commands.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados