Skip to content

--max-count has precedence over --after-context and --context #402

@chelmertz

Description

@chelmertz

I think --after-context (-A) and --context (-C) should have the same precedence as --before-context (-B), when being combined with --max-count (-m), but they do not:

$ cat > rgtest.txt <<EOF
> a
> b
> c
> d
> e
> EOF
$ rg -B2 c rgtest.txt
1-a
2-b
3:c
$ rg -C2 c rgtest.txt
1-a
2-b
3:c
4-d
5-e
$ rg -A2 c rgtest.txt
3:c
4-d
5-e
$ # and now with --max-count:
$ rg -B2 c -m1 rgtest.txt
1-a
2-b
3:c
$ rg -C2 c -m1 rgtest.txt
1-a
2-b
3:c
$ rg -A2 c -m1 rgtest.txt
3:c

From my expectations, -B works correctly, -C works like -B which is unexpected, and -A has no effect at all.

My use case is to show a colleague one instance of many repeated matches, but also with some context. If -A combined with -m would yield the same result as with -B, then my use case would have been fulfilled.

I am using ripgrep-0.3.2-1.fc24.x86_64, packaged for Fedora through copr (by carlgeorge-ripgrep).

Thanks for a great program! (edit: removed trailing whitespace in code block)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA bug.libripgrepAn issue related to modularizing ripgrep into libraries.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions