File tree Expand file tree Collapse file tree 2 files changed +41
-5
lines changed
Expand file tree Collapse file tree 2 files changed +41
-5
lines changed Original file line number Diff line number Diff line change @@ -405,6 +405,25 @@ export THEFUCK_PRIORITY='no_command=9999:apt_get=100'
405405export THEFUCK_HISTORY_LIMIT=' 2000'
406406```
407407
408+ ## Third-party packages with rules
409+
410+ If you want to make very specific rules or rules, that you don't want to make public,
411+ but share with other people.
412+ You can create a special package with name ` thefuck_contrib_* ` with following structure:
413+
414+ ```
415+ thefuck_contrib_foo
416+ thefuck_contrib_foo
417+ rules
418+ __init__.py
419+ *third-party rules*
420+ __init__.py
421+ *third-party-utils*
422+ setup.py
423+ ```
424+
425+ And thefuck will find all rules from ` rules ` module.
426+
408427## Experimental instant mode
409428
410429By default The Fuck reruns a previous command and that takes time,
Original file line number Diff line number Diff line change 1+ import sys
12from .conf import settings
23from .types import Rule
34from .system import Path
@@ -18,17 +19,33 @@ def get_loaded_rules(rules_paths):
1819 yield rule
1920
2021
22+ def get_rules_import_paths ():
23+ """Yields all rules import paths.
24+
25+ :rtype: Iterable[Path]
26+
27+ """
28+ # Bundled rules:
29+ yield Path (__file__ ).parent .joinpath ('rules' )
30+ # Rules defined by user:
31+ yield settings .user_dir .joinpath ('rules' )
32+ # Packages with third-party rules:
33+ for path in sys .path :
34+ for contrib_module in Path (path ).glob ('thefuck_contrib_*' ):
35+ contrib_rules = contrib_module .joinpath ('rules' )
36+ if contrib_rules .is_dir ():
37+ yield contrib_rules
38+
39+
2140def get_rules ():
2241 """Returns all enabled rules.
2342
2443 :rtype: [Rule]
2544
2645 """
27- bundled = Path (__file__ ).parent \
28- .joinpath ('rules' ) \
29- .glob ('*.py' )
30- user = settings .user_dir .joinpath ('rules' ).glob ('*.py' )
31- return sorted (get_loaded_rules (sorted (bundled ) + sorted (user )),
46+ paths = [rule_path for path in get_rules_import_paths ()
47+ for rule_path in sorted (path .glob ('*.py' ))]
48+ return sorted (get_loaded_rules (paths ),
3249 key = lambda rule : rule .priority )
3350
3451
You can’t perform that action at this time.
0 commit comments