mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-07 13:41:21 +00:00
Add a no_such_file
rule
This commit is contained in:
parent
371a4b0ad3
commit
3c4f9d50a9
@ -161,6 +161,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
|||||||
* `lein_not_task` – fixes wrong `lein` tasks like `lein rpl`;
|
* `lein_not_task` – fixes wrong `lein` tasks like `lein rpl`;
|
||||||
* `mkdir_p` – adds `-p` when you trying to create directory without parent;
|
* `mkdir_p` – adds `-p` when you trying to create directory without parent;
|
||||||
* `no_command` – fixes wrong console commands, for example `vom/vim`;
|
* `no_command` – fixes wrong console commands, for example `vom/vim`;
|
||||||
|
* `no_such_file` – creates missing directories with `mv` and `cp` commands;
|
||||||
* `man_no_space` – fixes man commands without spaces, for example `mandiff`;
|
* `man_no_space` – fixes man commands without spaces, for example `mandiff`;
|
||||||
* `pacman` – installs app with `pacman` or `yaourt` if it is not installed;
|
* `pacman` – installs app with `pacman` or `yaourt` if it is not installed;
|
||||||
* `pip_unknown_command` – fixes wrong pip commands, for example `pip instatl/pip install`;
|
* `pip_unknown_command` – fixes wrong pip commands, for example `pip instatl/pip install`;
|
||||||
|
26
thefuck/rules/no_such_file.py
Normal file
26
thefuck/rules/no_such_file.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
patterns = (
|
||||||
|
r"mv: cannot move '[^']*' to '([^']*)': No such file or directory",
|
||||||
|
r"cp: cannot create regular file '([^']*)': No such file or directory",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def match(command, settings):
|
||||||
|
for pattern in patterns:
|
||||||
|
if re.search(pattern, command.stderr):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def get_new_command(command, settings):
|
||||||
|
for pattern in patterns:
|
||||||
|
file = re.findall(pattern, command.stderr)
|
||||||
|
|
||||||
|
if file:
|
||||||
|
file = file[0]
|
||||||
|
dir = file[0:file.rfind('/')]
|
||||||
|
|
||||||
|
return 'mkdir -p {} && {}'.format(dir, command.script)
|
Loading…
x
Reference in New Issue
Block a user