Giter Club home page Giter Club logo

cgrep's Introduction

cgrep - conditional grep

This is just another variation of grep (because we needed more of those) that allows you to require or reject files before the normal grep process based upon patterns. For example, you could reject all patterns that include version :latest before matching the version pattern in a bunch of package manifest files.

Requires

This was built using C++17 and it uses the POSIX header file glob.h which I assume is only available on macOS and Linux. I tested it on macOS.

Building

make release
./cgrep

Examples

By default cgrep asks you to enter patterns at the command line.

$ cgrep src/*.cpp src/*.hpp --count
# Enter grep patterns starting with...
#   '+' for required patterns
#   '-' for rejected patterns
#   '=' for matched patterns
# Enter a blank line to submit.
> + <map> 
> + <vector>
> = #include
> 

src/grep_factory.hpp:4
src/output_strategy.hpp:5
src/parse_input.hpp:3

Those patterns can also be sourced from a file.

$ cgrep src/*.cpp src/*.hpp --count --pattern-file=patterns.txt
src/grep_factory.hpp:4
src/output_strategy.hpp:5
src/parse_input.hpp:3

patterns.txt

+ <map> 
+ <vector>
= #include

Also, the previous query can be rerun with the --again option.

$ cgrep src/*.cpp src/*.hpp --count --again
src/grep_factory.hpp:4
src/output_strategy.hpp:5
src/parse_input.hpp:3

Help Page

[cgrep]
-------
Conditionally grep files using multiple
required(+), rejected(-) and matched(=) patterns.
Required and rejected patterns are resolved
before returning matches.
   
[usage]
-------
cgrep [-acEhilLn] [-p=pattern-file] [-o=output-file] [file ...]
   
[options]
---------
-a / --again
   Rerun previous query again.
-c / --count
   Count the number of matched lines in each file.
-E / --extended-regexp
   Sets pattern matching to egrep.
-h / --help
   Shows this page.
-i / --ignore-case
   Sets grep to ignore case when matching.
-l / --files-with-matches
   Lists all files with matched lines.
-L / --files-without-matches
   Lists all files without matched lines in search set.
-n / --line-number
   Each output line is preceded by its relative line number.
-o= / --output-file=
   Writes results to a file.
-p= / --pattern-file=
   Reads grep patterns from a file.

cgrep's People

Contributors

apainintheneck avatar

Watchers

 avatar  avatar

cgrep's Issues

Rerun previous search

I think it would be a good idea to add some sort of command that reruns the previous search or allows you to save it as a query as described in #1. This would be especially helpful when making long complicated queries. Editing wouldn't necessarily be an option but you should be able to open it in a text editor yourself even though it isn't in the application per se.

Add the ability to bookmark common queries

Since cgrep allows you to make queries using pattern files, the next logical step would be to have some way to bookmark common queries. This would require some new flag like --query=query-name. Behind the scenes I think this could just function the same way as the pattern files but instead of requiring the path they would just be stored in some common location by their query name.

Example

$ cgrep -q=latest-casks *.rb

There should also be some way to bookmark the previous query as well. (Usually you want to try the query first before deciding if it's worth saving.) Queries could also be imported from pattern files as well.

Match patterns should not be required when `-l` or `-L` are set

The -l and -L options display filenames based upon match patterns currently. The thing is they don't actually show the matches just the filenames where the matches took place. It would make more sense for there to be no restrictions requiring match parameters (denoted by the equal sign) when either of these options is passed to the program.

This change would involve rewriting some of the validation code for patterns and the grep function to allow printing when a match pattern doesn't exist.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.