App-GitGrepPerlStatement

 view release on metacpan or  search on metacpan

bin/git-grep-perl-statement  view on Meta::CPAN


Ordinary git-grep shows matched line. git-grep-per-statement shows matched statement.

=head1 EXAMPLES

    % git grep-perl-statement colored
    git-grep-perl-statement:61
    colored($self->highlight_style, $_);
    git-grep-perl-statement:85
    say colored(
        ['bold'],
        "@{[ $file ]}:@{[ $_->line_number ]}"
    );

=head1 LICENSE

Copyright (C) hitode909.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

lib/App/GitGrepPerlStatement.pm  view on Meta::CPAN

    my @files = split "\n", `git grep --name-only --cached --word-regexp @{[ join ' ', map { quotemeta($_) } @argv ]}`;

    my $finder = App::GitGrepPerlStatement::StatementFinder->new($word);

    for my $file (@files) {
        my @found = $finder->search($file);

        for (@found) {
            if (-t STDOUT) {
                say colored(
                    ['bold'],
                    "@{[ $file ]}:@{[ $_->line_number ]}"
                );
                say $finder->highlight($_);
            } else {
                say "@{[ $file ]}:@{[ $_->line_number ]}";
                say $_;
            }
        }
        $finder->flush;
    }



( run in 0.326 second using v1.01-cache-2.11-cpan-5dc5da66d9d )