diff --git a/README.md b/README.md index 07445c3..2604b62 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,8 @@ sudo -H pip install thefuck --upgrade The Fuck tries to match a rule for the previous command, creates a new command using the matched rule and runs it. Rules enabled by default are as follows: -* `aws_cli` – fixes misspelled commands like `aws dynamdb scan` +* `ag_literal` – adds `-Q` to `ag` when suggested; +* `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`; * `cd_correction` – spellchecks and correct failed cd commands; diff --git a/tests/rules/test_ag_literal.py b/tests/rules/test_ag_literal.py new file mode 100644 index 0000000..4040d5d --- /dev/null +++ b/tests/rules/test_ag_literal.py @@ -0,0 +1,25 @@ +import pytest +from thefuck.rules.ag_literal import get_new_command, match +from tests.utils import Command + + +@pytest.fixture +def stderr(): + return ('ERR: Bad regex! pcre_compile() failed at position 1: missing )\n' + 'If you meant to search for a literal string, run ag with -Q\n') + + +@pytest.mark.parametrize('script', ['ag \(']) +def test_match(script, stderr): + assert match(Command(script=script, stderr=stderr)) + + +@pytest.mark.parametrize('script', ['ag foo']) +def test_not_match(script): + assert not match(Command(script=script)) + + +@pytest.mark.parametrize('script, new_cmd', [ + ('ag \(', 'ag -Q \(')]) +def test_get_new_command(script, new_cmd, stderr): + assert get_new_command((Command(script=script, stderr=stderr))) == new_cmd diff --git a/thefuck/rules/ag_literal.py b/thefuck/rules/ag_literal.py new file mode 100644 index 0000000..a07ae07 --- /dev/null +++ b/thefuck/rules/ag_literal.py @@ -0,0 +1,10 @@ +from thefuck.utils import for_app + + +@for_app('ag') +def match(command): + return command.stderr.endswith('run ag with -Q\n') + + +def get_new_command(command): + return command.script.replace('ag', 'ag -Q', 1)