mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 12:06:04 +00:00
#380 merge cd_mkdir
and cd_correction
rules
This commit is contained in:
parent
3da26192cb
commit
0fcc35c227
@ -141,8 +141,8 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
||||
|
||||
* `cargo` – runs `cargo build` instead of `cargo`;
|
||||
* `cargo_no_command` – fixes wrongs commands like `cargo buid`;
|
||||
* `cd_correction` – spellchecks and correct failed cd commands;
|
||||
* `cd_mkdir` – creates directories before cd'ing into them;
|
||||
* `cd_correction` – spellchecks and correct failed cd commands, when it's not possible
|
||||
creates directories before cd'ing into them;
|
||||
* `cd_parent` – changes `cd..` to `cd ..`;
|
||||
* `composer_not_command` – fixes composer command name;
|
||||
* `cp_omitting_directory` – adds `-a` when you `cp` directory;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import pytest
|
||||
from thefuck.rules.cd_mkdir import match, get_new_command
|
||||
from thefuck.rules.cd_correction import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
@ -2,9 +2,10 @@
|
||||
|
||||
import os
|
||||
from difflib import get_close_matches
|
||||
import re
|
||||
from thefuck.specific.sudo import sudo_support
|
||||
from thefuck.rules import cd_mkdir
|
||||
from thefuck.utils import for_app
|
||||
from thefuck import shells
|
||||
|
||||
__author__ = "mmussomele"
|
||||
|
||||
@ -43,11 +44,13 @@ def get_new_command(command):
|
||||
elif directory == "..":
|
||||
cwd = os.path.split(cwd)[0]
|
||||
continue
|
||||
best_matches = get_close_matches(directory, _get_sub_dirs(cwd), cutoff=MAX_ALLOWED_DIFF)
|
||||
best_matches = get_close_matches(
|
||||
directory, _get_sub_dirs(cwd), cutoff=MAX_ALLOWED_DIFF)
|
||||
if best_matches:
|
||||
cwd = os.path.join(cwd, best_matches[0])
|
||||
else:
|
||||
return cd_mkdir.get_new_command(command)
|
||||
repl = shells.and_('mkdir -p \\1', 'cd \\1')
|
||||
return re.sub(r'^cd (.*)', repl, command.script)
|
||||
return 'cd "{0}"'.format(cwd)
|
||||
|
||||
|
||||
|
@ -1,17 +0,0 @@
|
||||
import re
|
||||
from thefuck import shells
|
||||
from thefuck.utils import for_app
|
||||
from thefuck.specific.sudo import sudo_support
|
||||
|
||||
|
||||
@sudo_support
|
||||
@for_app('cd')
|
||||
def match(command):
|
||||
return (('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):
|
||||
repl = shells.and_('mkdir -p \\1', 'cd \\1')
|
||||
return re.sub(r'^cd (.*)', repl, command.script)
|
Loading…
Reference in New Issue
Block a user