diff --git a/tests/rules/test_rm_dir.py b/tests/rules/test_rm_dir.py index c334d2ff..84ba4434 100644 --- a/tests/rules/test_rm_dir.py +++ b/tests/rules/test_rm_dir.py @@ -18,4 +18,4 @@ def test_not_match(command): def test_get_new_command(): - assert get_new_command(Command('rm foo', '', ''), None) == 'rm -rf foo' + assert get_new_command(Command('rm foo', '', ''), None) == 'rmdir foo' diff --git a/thefuck/rules/rm_dir.py b/thefuck/rules/rm_dir.py index 89b1d2bb..7254d8fb 100644 --- a/thefuck/rules/rm_dir.py +++ b/thefuck/rules/rm_dir.py @@ -10,4 +10,4 @@ def match(command, settings): @sudo_support def get_new_command(command, settings): - return re.sub('^rm (.*)', 'rm -rf \\1', command.script) + return re.sub('^rm (.*)', 'rmdir \\1', command.script) diff --git a/thefuck/rules/rmdir.py b/thefuck/rules/rmdir.py new file mode 100644 index 00000000..fd446ed7 --- /dev/null +++ b/thefuck/rules/rmdir.py @@ -0,0 +1,9 @@ +import re + +def match(command, settings): + return ('rmdir' in command.script + and 'Directory not empty' in command.stderr) + + +def get_new_command(command, settings): + return re.sub('^rm (.*)', 'rm -rf \\1', command.script)