diff --git a/README.md b/README.md index f18fafb0..620d2360 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,10 @@ using matched rule and run it. Rules enabled by default: * `sudo` – prepends `sudo` to previous command if it failed because of permissions; * `switch_layout` – switches command from your local layout to en. +Bundled, but not enabled by default: + +* `rm_root` – adds `--no-preserve-root` to `rm -rf /` command. + ## Creating your own rules For adding your own rule you should create `your-rule-name.py` diff --git a/thefuck/main.py b/thefuck/main.py index a6c24ee5..32c1c7c8 100644 --- a/thefuck/main.py +++ b/thefuck/main.py @@ -153,7 +153,8 @@ def main(): logs.failed("Can't fuck twice", settings) return - rules = get_rules(user_dir, settings) + rules = list(get_rules(user_dir, settings)) + sys.stderr.write(str([r.name for r in rules]) + '\n') matched_rule = get_matched_rule(command, rules, settings) if matched_rule: run_rule(matched_rule, command, settings) diff --git a/thefuck/rules/rm_root.py b/thefuck/rules/rm_root.py new file mode 100644 index 00000000..fc75332d --- /dev/null +++ b/thefuck/rules/rm_root.py @@ -0,0 +1,11 @@ +enabled_by_default = False + + +def match(command, settings): + return ({'rm', '/'}.issubset(command.script.split()) + and '--no-preserve-root' not in command.script + and '--no-preserve-root' in command.stderr) + + +def get_new_command(command, settings): + return '{} --no-preserve-root'.format(command.script)