Add information about writting yourself rules, revert no_command changes

This commit is contained in:
nvbn
2015-04-17 17:01:30 +02:00
parent 1503dcf294
commit 1de9c5f77b
5 changed files with 82 additions and 16 deletions
+34
View File
@@ -61,6 +61,40 @@ And add to `.bashrc` or `.zshrc`:
alias fuck='$(thefuck $(fc -ln -1))'
```
## Creating your own rules
For adding your own rule you should create `your-rule-name.py`
in `~/.thefuck/rules`. Rule should contain two functions:
`match(command: Command, settings: Settings) -> bool`
and `get_new_command(command: Command, settings: Settings) -> str`.
`Command` have three attributes: `script`, `stdout` and `stderr`.
`Settings` is `~/.thefuck/settings.py`.
Simple example of the rule for running script with `sudo`:
```python
def match(command, settings):
return ('permission denied' in command.stderr.lower()
or 'EACCES' in command.stderr)
def get_new_command(command, settings):
return 'sudo {}'.format(command.script)
```
[More examples of rules](https://github.com/nvbn/thefuck/tree/master/thefuck/rules),
[utility functions for rules]((https://github.com/nvbn/thefuck/tree/master/thefuck/utils.py)).
## Settings
The Fuck have a few settings parameters:
* `rules` – list of enabled rules, by default all;
* `command_not_found` – path to `command_not_found` binary,
by default `/usr/lib/command-not-found`.
## Developing
Install `The Fuck` for development: