Magnificent app which corrects your previous console command
npx @tessl/cli install tessl/pypi-thefuck@2.9.0A magnificent command-line utility that corrects mistyped or failed console commands by intelligently analyzing command output and context to suggest appropriate fixes. It helps users quickly correct common command errors, typos, and mistakes across multiple shells and command-line tools using a sophisticated rule-based correction system.
pip install thefuckthefuck, thefuck-alias (deprecated)Main application modules:
import thefuck.main
import thefuck.types
import thefuck.conf
import thefuck.correctorCommon programmatic usage:
from thefuck.main import get_command, get_corrected_commands
from thefuck.types import Command, Settings
from thefuck.conf import get_settings
from thefuck.corrector import get_corrected_commandsthefuck to get suggested corrections# Example: Typo in git command
$ git pussh origin main
git: 'pussh' is not a git command. See 'git --help'.
$ thefuck
git push origin main [enter/↑/↓/ctrl+c]
git push origin master [enter/↑/↓/ctrl+c]Install shell alias for quick correction:
# Get alias for your shell
$ thefuck --alias
# Add to shell configuration
alias fuck='TF_ALIAS=fuck eval $(thefuck $(fc -ln -1))'Then use the alias after failed commands:
$ apt-get install vim
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
$ fuck
sudo apt-get install vim [enter/↑/↓/ctrl+c]import sys
from thefuck.main import setup_user_dir, get_command
from thefuck.conf import get_settings
from thefuck.corrector import get_corrected_commands
from thefuck.ui import select_command
# Setup
user_dir = setup_user_dir()
settings = get_settings(user_dir)
# Get failed command (example: from command line args)
command = get_command(settings, ['thefuck', 'git', 'pussh', 'origin', 'main'])
# Get corrections
corrected_commands = get_corrected_commands(command, user_dir, settings)
# Select correction (interactive or automatic)
selected = select_command(corrected_commands, settings)
if selected:
print(f"Suggested correction: {selected.script}")The Fuck uses a modular architecture with several key components:
main.py)types.py)conf.py)corrector.py)shells.py)ui.py)utils.py)Main application entry points, command processing, and execution functionality. These functions provide the foundation for command correction and user interaction.
def main(): ...
def fix_command(): ...
def setup_user_dir(): ...
def get_command(settings, args): ...
def run_command(old_cmd, command, settings): ...Essential data types representing commands, rules, corrections, and settings. These classes form the foundation of the correction system and provide structured data handling.
class Command: ...
class Rule: ...
class CorrectedCommand: ...
class Settings: ...
class SortedCorrectedCommandsSequence: ...Settings management from configuration files and environment variables, supporting user customization of correction behavior, rule selection, and application preferences.
def get_settings(user_dir): ...
def initialize_settings_file(user_dir): ...Rule loading, command matching, and correction generation. This system processes failed commands through available rules to generate appropriate corrections.
def load_rule(rule, settings): ...
def get_rules(user_dir, settings): ...
def get_corrected_commands(command, user_dir, settings): ...
def is_rule_match(command, rule, settings): ...Interactive command selection, keyboard input handling, and user confirmation interfaces for selecting and executing corrections.
class CommandSelector: ...
def select_command(corrected_commands, settings): ...
def read_actions(): ...Multi-shell support for command history, aliases, and shell-specific functionality across bash, zsh, fish, tcsh, and PowerShell environments.
class Generic: ...
def from_shell(command): ...
def app_alias(alias): ...
def put_to_history(command): ...Common utility functions, decorators, and helper tools used throughout the application for caching, string matching, command manipulation, and application detection.
def memoize(fn): ...
def which(program): ...
def get_closest(word, possibilities): ...
def for_app(app): ...Creating custom correction rules, rule structure, and integration patterns. This enables extending the correction system with new command-specific logic.
def match(command, settings): ...
def get_new_command(command, settings): ...