How nvbn/thefuck works
The Fuck is a command-line assistant that diagnoses a failed previous shell command, proposes rule-based corrections, and optionally runs a selected correction. The main path runs from shell alias or CLI invocation through argument and history handling, command construction, correction matching, interactive selection, and execution. Shell-specific adapters, configurable settings, output readers, and logging support that workflow. The README documents broad rule coverage and confirmation/repeat options; individual rule implementations are not sampled, so their internal matching details are not expanded here.
Main entry points: fix_command.py Fix command · main.py Command dispatcher · conf.py Settings · types.py Command model
Components 19
CLI and shell entry
- CLI launcher
fastentrypoints.py - Command dispatcher
thefuck/entrypoints/main.py - Argument parser
thefuck/argument_parser.py - Alias generation
thefuck/entrypoints/alias.py - Shell logger
thefuck/entrypoints/shell_logger.py
Correction workflow
- Fix command
thefuck/entrypoints/fix_command.py - Command model
thefuck/types.py - Correction engine
thefuck/corrector.py - Command selection
thefuck/ui.py - Output readers
thefuck/output_readers
Rules and configuration
- Correction rules
thefuck/rules - Settings
thefuck/conf.py - Runtime constants
thefuck/const.py - Logging and feedback
thefuck/logs.py
Shell and platform support
- Shell adapters
thefuck/shells - OS interface
thefuck/system - Shared utilities
thefuck/utils.py - Runtime exceptions
thefuck/exceptions.py
Other components
- Shell user
Connections 26
- Shell user → CLI launcher: invokes
README.md - CLI launcher → Command dispatcher: starts
- Command dispatcher → Argument parser: parses arguments
thefuck/entrypoints/main.py - Command dispatcher → Alias generation: requests alias
thefuck/entrypoints/main.py - Command dispatcher → Fix command: dispatches fixes
thefuck/entrypoints/main.py - Command dispatcher → Shell logger: dispatches logging
thefuck/entrypoints/main.py - Alias generation → Shell adapters: formats shell alias
thefuck/entrypoints/alias.py - Fix command → Settings: initializes
thefuck/entrypoints/fix_command.py - Fix command → Command model: builds command
thefuck/entrypoints/fix_command.py - Fix command → Correction engine: requests candidates
thefuck/entrypoints/fix_command.py - Correction engine → Correction rules: matches rules
README.md - Correction engine → Command model: uses command model
thefuck/corrector.py - Fix command → Command selection: selects candidate
thefuck/entrypoints/fix_command.py - Command selection → Command model: runs selected command
- Command model → Output readers: reads command output
thefuck/types.py - Fix command → Runtime exceptions: handles empty command
thefuck/entrypoints/fix_command.py - Argument parser → Runtime constants: uses placeholder
thefuck/argument_parser.py - Settings → Runtime constants: loads defaults
thefuck/conf.py - Settings → OS interface: uses platform paths
thefuck/conf.py - Fix command → Logging and feedback: reports workflow
thefuck/entrypoints/fix_command.py - Output readers → Logging and feedback: reports read failures
thefuck/output_readers/read_log.py - Shell adapters → Settings: uses shell settings
thefuck/shells/fish.py - Shell adapters → Shared utilities: uses shared helpers
thefuck/shells/fish.py - Shared utilities → OS interface: uses platform paths
thefuck/utils.py - Shell logger → Logging and feedback: logs shell output
thefuck/entrypoints/shell_logger.py - Fix command → Shared utilities: finds history executables
thefuck/entrypoints/fix_command.py