diff --git a/thefuck/rules/cd_correction.py b/thefuck/rules/cd_correction.py index 442ccf24..bdd7c34b 100644 --- a/thefuck/rules/cd_correction.py +++ b/thefuck/rules/cd_correction.py @@ -4,22 +4,25 @@ __author__ = "mmussomele" """Attempts to spellcheck and correct failed cd commands""" import os -import cd_mkdir from difflib import get_close_matches from thefuck.utils import sudo_support +from thefuck.rules import cd_mkdir MAX_ALLOWED_DIFF = 0.6 + def _get_sub_dirs(parent): """Returns a list of the child directories of the given parent directory""" return [child for child in os.listdir(parent) if os.path.isdir(os.path.join(parent, child))] + @sudo_support def match(command, settings): """Match function copied from cd_mkdir.py""" return (command.script.startswith('cd ') - and ('no such file or directory' in command.stderr.lower() - or 'cd: can\'t cd to' in command.stderr.lower())) + and ('no such file or directory' in command.stderr.lower() + or 'cd: can\'t cd to' in command.stderr.lower())) + @sudo_support def get_new_command(command, settings): @@ -44,6 +47,7 @@ def get_new_command(command, settings): cwd = os.path.join(cwd, best_matches[0]) else: return cd_mkdir.get_new_command(command, settings) - return "cd {0}".format(cwd) + return "cd {0}".format(cwd) + enabled_by_default = True