From 2a79a5e413b41bbbe3886828a97958ca824e7bdc Mon Sep 17 00:00:00 2001 From: SpyCheese Date: Sun, 19 Apr 2015 09:03:34 +0500 Subject: [PATCH 1/4] Create rm_root.py --- thefuck/rules/rm_root.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 thefuck/rules/rm_root.py diff --git a/thefuck/rules/rm_root.py b/thefuck/rules/rm_root.py new file mode 100644 index 00000000..95d9fbdd --- /dev/null +++ b/thefuck/rules/rm_root.py @@ -0,0 +1,8 @@ +def match(command, settings): + return ('rm' in command.script + and '--help' not in command.script + and '--no-preserve-root' in command.stderr) + + +def get_new_command(command, settings): + return '{} --no-preserve-root'.format(command.script) From f113bae59d97ab1cd90857680e8c6e9320b96327 Mon Sep 17 00:00:00 2001 From: SpyCheese Date: Sun, 19 Apr 2015 09:12:19 +0500 Subject: [PATCH 2/4] Update rm_root.py --- thefuck/rules/rm_root.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thefuck/rules/rm_root.py b/thefuck/rules/rm_root.py index 95d9fbdd..b97eda22 100644 --- a/thefuck/rules/rm_root.py +++ b/thefuck/rules/rm_root.py @@ -1,6 +1,6 @@ def match(command, settings): - return ('rm' in command.script - and '--help' not in command.script + return ('/' in command.script + and '--no-preserve-root' not in command.script and '--no-preserve-root' in command.stderr) From ceeccf1cd7de156ae48ce5aa7f01366015fa6de9 Mon Sep 17 00:00:00 2001 From: SpyCheese Date: Sun, 19 Apr 2015 10:21:46 +0500 Subject: [PATCH 3/4] Update rm_root.py Okay, there was an incorrect match function. --- thefuck/rules/rm_root.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thefuck/rules/rm_root.py b/thefuck/rules/rm_root.py index b97eda22..853ce847 100644 --- a/thefuck/rules/rm_root.py +++ b/thefuck/rules/rm_root.py @@ -1,5 +1,5 @@ def match(command, settings): - return ('/' in command.script + return ('/' in command.script.split() and '--no-preserve-root' not in command.script and '--no-preserve-root' in command.stderr) From fa4e4522b78ccf0811e8b6b671a20fab6099c1f2 Mon Sep 17 00:00:00 2001 From: nvbn Date: Wed, 22 Apr 2015 16:08:54 +0200 Subject: [PATCH 4/4] #43 Add `rm_root` as disabled by default rule --- README.md | 4 ++++ thefuck/main.py | 3 ++- thefuck/rules/rm_root.py | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) 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 index 853ce847..fc75332d 100644 --- a/thefuck/rules/rm_root.py +++ b/thefuck/rules/rm_root.py @@ -1,5 +1,8 @@ +enabled_by_default = False + + def match(command, settings): - return ('/' in command.script.split() + return ({'rm', '/'}.issubset(command.script.split()) and '--no-preserve-root' not in command.script and '--no-preserve-root' in command.stderr)