■ ■ ■ ■ ■ ■
thefuck/rules/cd_correction.py
| skipped 1 lines |
2 | 2 | | |
3 | 3 | | import os |
4 | 4 | | from difflib import get_close_matches |
| 5 | + | import re |
5 | 6 | | from thefuck.specific.sudo import sudo_support |
6 | | - | from thefuck.rules import cd_mkdir |
7 | 7 | | from thefuck.utils import for_app |
| 8 | + | from thefuck import shells |
8 | 9 | | |
9 | 10 | | __author__ = "mmussomele" |
10 | 11 | | |
| skipped 32 lines |
43 | 44 | | elif directory == "..": |
44 | 45 | | cwd = os.path.split(cwd)[0] |
45 | 46 | | continue |
46 | | - | best_matches = get_close_matches(directory, _get_sub_dirs(cwd), cutoff=MAX_ALLOWED_DIFF) |
| 47 | + | best_matches = get_close_matches( |
| 48 | + | directory, _get_sub_dirs(cwd), cutoff=MAX_ALLOWED_DIFF) |
47 | 49 | | if best_matches: |
48 | 50 | | cwd = os.path.join(cwd, best_matches[0]) |
49 | 51 | | else: |
50 | | - | return cd_mkdir.get_new_command(command) |
| 52 | + | repl = shells.and_('mkdir -p \\1', 'cd \\1') |
| 53 | + | return re.sub(r'^cd (.*)', repl, command.script) |
51 | 54 | | return 'cd "{0}"'.format(cwd) |
52 | 55 | | |
53 | 56 | | |
| skipped 2 lines |