mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-14 14:48:49 +00:00
Create cat_dir
rule for replacing cat
with ls
when you try to run cat
on a directory.
This commit is contained in:
parent
86efc6a252
commit
d52765ff84
@ -177,6 +177,7 @@ following rules are enabled by default:
|
||||
* `aws_cli` – fixes misspelled commands like `aws dynamdb scan`;
|
||||
* `cargo` – runs `cargo build` instead of `cargo`;
|
||||
* `cargo_no_command` – fixes wrongs commands like `cargo buid`;
|
||||
* `cat_dir` – replaces `cat` with `ls` when you try to `cat` a directory
|
||||
* `cd_correction` – spellchecks and correct failed cd commands;
|
||||
* `cd_mkdir` – creates directories before cd'ing into them;
|
||||
* `cd_parent` – changes `cd..` to `cd ..`;
|
||||
|
28
tests/rules/test_cat_dir.py
Normal file
28
tests/rules/test_cat_dir.py
Normal file
@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
from thefuck.rules.cat_dir import match, get_new_command
|
||||
from thefuck.types import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command('cat foo', 'cat: foo: Is a directory'),
|
||||
Command('cat /foo/bar/', 'cat: /foo/bar/: Is a directory'),
|
||||
])
|
||||
def test_match(command):
|
||||
assert match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command('cat foo', 'foo bar baz'),
|
||||
Command('cat foo bar', 'foo bar baz'),
|
||||
Command('', ''),
|
||||
])
|
||||
def test_not_match(command):
|
||||
assert not match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('cat foo', 'cat: foo: Is a directory'), 'ls foo'),
|
||||
(Command('cat /foo/bar/', 'cat: /foo/bar/: Is a directory'), 'ls /foo/bar/'),
|
||||
])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command) == new_command
|
12
thefuck/rules/cat_dir.py
Normal file
12
thefuck/rules/cat_dir.py
Normal file
@ -0,0 +1,12 @@
|
||||
import re
|
||||
|
||||
|
||||
def match(command):
|
||||
return (
|
||||
command.script.startswith('cat') and
|
||||
re.match(r'cat: .+: Is a directory', command.output)
|
||||
)
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
return re.sub(r'^cat', 'ls', command.script)
|
Loading…
x
Reference in New Issue
Block a user