Magnificent app which corrects your previous console command
Main application entry points, command processing, and execution functionality. These functions provide the foundation for command correction and user interaction in the thefuck application.
The primary CLI entry points that handle argument parsing and dispatch to appropriate functionality.
def main():
"""
Main CLI entry point with argument parsing.
Handles command-line arguments including:
- --version: Show version information
- --alias: Print shell alias configuration
- command arguments: Process command for correction
Returns:
None
"""
def fix_command():
"""
Main entry point for command correction functionality.
Sets up user directory, loads settings, processes the command from
sys.argv, generates corrections, and handles user interaction.
Returns:
None
"""
def print_alias(entry_point=True):
"""
Prints shell alias configuration for thefuck integration.
Parameters:
- entry_point (bool): Whether called from deprecated thefuck-alias entry point
Returns:
None
Prints shell-specific alias command to stdout.
"""Functions for managing the user's thefuck configuration directory and initialization.
def setup_user_dir():
"""
Returns user config dir, creates it when it doesn't exist.
Creates ~/.thefuck directory structure including:
- Main configuration directory
- Rules subdirectory for custom rules
- Settings file initialization
Returns:
pathlib.Path: Path to user configuration directory
"""Core command execution and processing functionality.
def get_command(settings, args):
"""
Creates command from args and executes it.
Parameters:
- settings (Settings): Application settings
- args (list): Command line arguments (typically sys.argv)
Returns:
Command: Command object with script, stdout, stderr or None if empty command
Executes the command with proper environment and timeout handling.
"""
def wait_output(settings, popen):
"""
Returns True if we can get output of the command in the settings.wait_command time.
Parameters:
- settings (Settings): Application settings containing wait_command timeout
- popen (subprocess.Popen): Process to wait for
Returns:
bool: True if command completed within timeout, False if killed due to timeout
Command will be killed if it wasn't finished in time.
"""
def run_command(old_cmd, command, settings):
"""
Runs command from rule for passed command.
Parameters:
- old_cmd (Command): Original failed command
- command (CorrectedCommand): Corrected command to execute
- settings (Settings): Application settings
Returns:
None
Executes side effects, adds to shell history, and prints the command.
"""import sys
from thefuck.main import setup_user_dir, get_command, fix_command
from thefuck.conf import get_settings
# Setup user environment
user_dir = setup_user_dir()
settings = get_settings(user_dir)
# Process a command
command = get_command(settings, ['thefuck', 'git', 'status'])
if command:
print(f"Executed: {command.script}")
print(f"Output: {command.stdout}")
print(f"Errors: {command.stderr}")from thefuck.main import print_alias
import sys
# Simulate thefuck --alias call
sys.argv = ['thefuck', '--alias', 'f']
print_alias(False) # Prints shell-specific alias configurationfrom thefuck.main import setup_user_dir, get_command, run_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)
# Process failed command
args = ['thefuck', 'git', 'pussh', 'origin', 'main']
command = get_command(settings, args)
if command:
# Get corrections
corrected_commands = get_corrected_commands(command, user_dir, settings)
# Select correction (interactive)
selected = select_command(corrected_commands, settings)
if selected:
# Execute the correction
run_command(command, selected, settings)Functions handle various error conditions:
get_command returns None for empty inputwait_output kills processes that exceed time limitsThe core application functions integrate with the system environment:
Install with Tessl CLI
npx tessl i tessl/pypi-thefuck