or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdcore-application.mddata-types.mdindex.mdrule-development.mdrule-system.mdshell-integration.mduser-interface.mdutilities.md
tile.json

tessl/pypi-thefuck

Magnificent app which corrects your previous console command

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/thefuck@2.9.x

To install, run

npx @tessl/cli install tessl/pypi-thefuck@2.9.0

index.mddocs/

The Fuck

A 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.

Package Information

  • Package Name: thefuck
  • Language: Python
  • Installation: pip install thefuck
  • CLI Commands: thefuck, thefuck-alias (deprecated)

Core Imports

Main application modules:

import thefuck.main
import thefuck.types
import thefuck.conf
import thefuck.corrector

Common 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_commands

Basic Usage

Command Line Usage

  1. Run a command that fails or has errors
  2. Run thefuck to get suggested corrections
  3. Select and execute the correction
# 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]

Shell Integration

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]

Programmatic Usage

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}")

Architecture

The Fuck uses a modular architecture with several key components:

  • Main Application: Entry points and command execution (main.py)
  • Type System: Core data structures for commands, rules, and settings (types.py)
  • Configuration: Settings management from files and environment (conf.py)
  • Corrector: Rule loading and correction generation (corrector.py)
  • Rules System: 70+ built-in correction rules for various CLI tools
  • Shell Integration: Multi-shell support for history and aliases (shells.py)
  • User Interface: Interactive command selection (ui.py)
  • Utilities: Common helper functions and decorators (utils.py)

Capabilities

Core Application Functions

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): ...

Core Application

Data Types and Structures

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: ...

Data Types

Configuration Management

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): ...

Configuration

Rule System and Correction

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): ...

Rule System

User Interface and Interaction

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(): ...

User Interface

Shell Integration

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): ...

Shell Integration

Utilities and Helpers

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): ...

Utilities

Rule Development

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): ...

Rule Development