Magnificent app which corrects your previous console command
npx @tessl/cli install tessl/pypi-thefuck@2.9.00
# The Fuck
1
2
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.
3
4
## Package Information
5
6
- **Package Name**: thefuck
7
- **Language**: Python
8
- **Installation**: `pip install thefuck`
9
- **CLI Commands**: `thefuck`, `thefuck-alias` (deprecated)
10
11
## Core Imports
12
13
Main application modules:
14
15
```python
16
import thefuck.main
17
import thefuck.types
18
import thefuck.conf
19
import thefuck.corrector
20
```
21
22
Common programmatic usage:
23
24
```python
25
from thefuck.main import get_command, get_corrected_commands
26
from thefuck.types import Command, Settings
27
from thefuck.conf import get_settings
28
from thefuck.corrector import get_corrected_commands
29
```
30
31
## Basic Usage
32
33
### Command Line Usage
34
35
1. Run a command that fails or has errors
36
2. Run `thefuck` to get suggested corrections
37
3. Select and execute the correction
38
39
```bash
40
# Example: Typo in git command
41
$ git pussh origin main
42
git: 'pussh' is not a git command. See 'git --help'.
43
44
$ thefuck
45
git push origin main [enter/↑/↓/ctrl+c]
46
git push origin master [enter/↑/↓/ctrl+c]
47
```
48
49
### Shell Integration
50
51
Install shell alias for quick correction:
52
53
```bash
54
# Get alias for your shell
55
$ thefuck --alias
56
57
# Add to shell configuration
58
alias fuck='TF_ALIAS=fuck eval $(thefuck $(fc -ln -1))'
59
```
60
61
Then use the alias after failed commands:
62
63
```bash
64
$ apt-get install vim
65
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
66
67
$ fuck
68
sudo apt-get install vim [enter/↑/↓/ctrl+c]
69
```
70
71
### Programmatic Usage
72
73
```python
74
import sys
75
from thefuck.main import setup_user_dir, get_command
76
from thefuck.conf import get_settings
77
from thefuck.corrector import get_corrected_commands
78
from thefuck.ui import select_command
79
80
# Setup
81
user_dir = setup_user_dir()
82
settings = get_settings(user_dir)
83
84
# Get failed command (example: from command line args)
85
command = get_command(settings, ['thefuck', 'git', 'pussh', 'origin', 'main'])
86
87
# Get corrections
88
corrected_commands = get_corrected_commands(command, user_dir, settings)
89
90
# Select correction (interactive or automatic)
91
selected = select_command(corrected_commands, settings)
92
93
if selected:
94
print(f"Suggested correction: {selected.script}")
95
```
96
97
## Architecture
98
99
The Fuck uses a modular architecture with several key components:
100
101
- **Main Application**: Entry points and command execution (`main.py`)
102
- **Type System**: Core data structures for commands, rules, and settings (`types.py`)
103
- **Configuration**: Settings management from files and environment (`conf.py`)
104
- **Corrector**: Rule loading and correction generation (`corrector.py`)
105
- **Rules System**: 70+ built-in correction rules for various CLI tools
106
- **Shell Integration**: Multi-shell support for history and aliases (`shells.py`)
107
- **User Interface**: Interactive command selection (`ui.py`)
108
- **Utilities**: Common helper functions and decorators (`utils.py`)
109
110
## Capabilities
111
112
### Core Application Functions
113
114
Main application entry points, command processing, and execution functionality. These functions provide the foundation for command correction and user interaction.
115
116
```python { .api }
117
def main(): ...
118
def fix_command(): ...
119
def setup_user_dir(): ...
120
def get_command(settings, args): ...
121
def run_command(old_cmd, command, settings): ...
122
```
123
124
[Core Application](./core-application.md)
125
126
### Data Types and Structures
127
128
Essential data types representing commands, rules, corrections, and settings. These classes form the foundation of the correction system and provide structured data handling.
129
130
```python { .api }
131
class Command: ...
132
class Rule: ...
133
class CorrectedCommand: ...
134
class Settings: ...
135
class SortedCorrectedCommandsSequence: ...
136
```
137
138
[Data Types](./data-types.md)
139
140
### Configuration Management
141
142
Settings management from configuration files and environment variables, supporting user customization of correction behavior, rule selection, and application preferences.
143
144
```python { .api }
145
def get_settings(user_dir): ...
146
def initialize_settings_file(user_dir): ...
147
```
148
149
[Configuration](./configuration.md)
150
151
### Rule System and Correction
152
153
Rule loading, command matching, and correction generation. This system processes failed commands through available rules to generate appropriate corrections.
154
155
```python { .api }
156
def load_rule(rule, settings): ...
157
def get_rules(user_dir, settings): ...
158
def get_corrected_commands(command, user_dir, settings): ...
159
def is_rule_match(command, rule, settings): ...
160
```
161
162
[Rule System](./rule-system.md)
163
164
### User Interface and Interaction
165
166
Interactive command selection, keyboard input handling, and user confirmation interfaces for selecting and executing corrections.
167
168
```python { .api }
169
class CommandSelector: ...
170
def select_command(corrected_commands, settings): ...
171
def read_actions(): ...
172
```
173
174
[User Interface](./user-interface.md)
175
176
### Shell Integration
177
178
Multi-shell support for command history, aliases, and shell-specific functionality across bash, zsh, fish, tcsh, and PowerShell environments.
179
180
```python { .api }
181
class Generic: ...
182
def from_shell(command): ...
183
def app_alias(alias): ...
184
def put_to_history(command): ...
185
```
186
187
[Shell Integration](./shell-integration.md)
188
189
### Utilities and Helpers
190
191
Common utility functions, decorators, and helper tools used throughout the application for caching, string matching, command manipulation, and application detection.
192
193
```python { .api }
194
def memoize(fn): ...
195
def which(program): ...
196
def get_closest(word, possibilities): ...
197
def for_app(app): ...
198
```
199
200
[Utilities](./utilities.md)
201
202
### Rule Development
203
204
Creating custom correction rules, rule structure, and integration patterns. This enables extending the correction system with new command-specific logic.
205
206
```python { .api }
207
def match(command, settings): ...
208
def get_new_command(command, settings): ...
209
```
210
211
[Rule Development](./rule-development.md)