
CGrep: a context-aware grep for source codes - psibi
http://awgn.github.io/cgrep/
======
gingerlime
This looks like a cool idea. I think a couple of (neat!) examples, stuff you
can't easily do with normal grep, will go a very long way. The list of
features is secondary in my opinion.

~~~
stcredzero
You basically had this with the Smalltalk refactoring Browser, where each
search popped up displayed in a browser window. Then you could easily AND such
searches together by executing a script in the browser window. Slightly more
sophisticated combinations were possible with just a few lines of scripting.

On top of that, everything above applied to syntax-driven rewrites and
refactorings.

------
bogolisk
blah.c:

    
    
      void foo(item *x)
      {
          x->blah(1, 2, 3);
          x->blah (4, 5,
                6);
          blah (7, 5, 1);
          foo (4, 5, 6);
          x->blah (4,
                5, 6);
      }
      
      
      void foo2(item y, item *x)
      {
          y.blah(1, 2, 3);
          y.blah (4, 5,
                6);
          blah (7, 5, 1);
          foo (4, 5, 6);
          x->blah (4,
                5, 6);
      }
    

search in blah.c for a call to _blah()_ with _5_ as 2nd argument from any
structure or pointer.

    
    
      cgrep --code --semantic '_1 . OR -> blah ( _2 , 5, _3 )' blah.c 
    
    

output:

    
    
      blah.c:6:    x->blah (4, 5,
      blah.c:7:          6);
      blah.c:10:    x->blah (4,
      blah.c:11:          5, 6);
      blah.c:18:    y.blah (4, 5,
      blah.c:19:          6);
      blah.c:22:    x->blah (4,
      blah.c:23:          5, 6);

------
egonschiele
I've thought about something like this before, and I'm really excited to see
how fully-featured it is. Written in Haskell is also a big plus.

------
ushi
Funny, there was a bell-labs project with same name. It seems to be dead[0],
but when we travel the time a few years back, we get a wonderful project
homepage[1].

[0] [http://www1.bell-labs.com/project/wwexptools/cgrep/](http://www1.bell-
labs.com/project/wwexptools/cgrep/)

[1]
[https://web.archive.org/web/20080513225010/http://www1.bell-...](https://web.archive.org/web/20080513225010/http://www1.bell-
labs.com/project/wwexptools/cgrep/)

------
chris_wot
I'm not sure where the documentation is.

~~~
timdorr
It's in the README at the repo:
[https://github.com/awgn/cgrep](https://github.com/awgn/cgrep)

~~~
chris_wot
Any examples?

------
edderly
I was curious, but had no idea how to use this on Ubuntu

sudo apt-get install haskell-platform

download and extract the tarball

cd awgn-cgrep-8af1beb

cabal cgrep.cabal

Unfortunately what stops me using it on a large codebase is that I can't
exclude directories like .repo (not sure about .git).

------
githulhu
Darn, no SQL support. I often find myself wishing something like this existed
for SQL, so I could, say, find all places where field X in table Y is updated,
or referenced in a WHERE clause predicate, etc.

~~~
mh-
interesting request; I've wanted something like this before but never enough
to really look for it.

I'm surprised there isn't a tool that can do this already.. perhaps under the
guise of refactoring?

------
yawniek
a binary for os x would be nice, since installing cabal/ghc currently is a bit
of a pain

~~~
mattgreenrocks
Isn't that just a brew install away?

~~~
oinksoft
It is a package install away:
[http://www.haskell.org/platform/mac.html](http://www.haskell.org/platform/mac.html)

On my machine it is significantly slower than `ag` (Silver Searcher) for basic
searches, but it should install and run.

~~~
yawniek
ok thats a way. i usually like to install stuff with homebrew.

------
cheez
How do I build this for Windows? I think I have something Haskell related
installed because I see lambda as an icon on the .hs files.

------
jasonlfunk
What is the difference between this and ack?

[http://beyondgrep.com](http://beyondgrep.com)

~~~
netghost
This is aware of some basic language semantics like literals, identifiers,
etc. Or so it seems. Peek at the github page
[https://github.com/awgn/cgrep](https://github.com/awgn/cgrep) for a little
more info.

------
mcrider
Would love a UI for this and an editor -- I still use TextWrangler/BBEdit
daily to grep large chunks of source code and then edit in place (e.g. for
refactoring). Just getting the search results requires opening up each file
individually then editing, which is just too slow.

------
michaelmior
JSON output is incredibly useful in combination with jq[1] for processing the
output. Some things become much easier than with standard *nix tools IMO.

[1] [http://stedolan.github.io/jq/](http://stedolan.github.io/jq/)

------
nodivbyzero
Have you tried [https://github.com/zeux/qgrep](https://github.com/zeux/qgrep)
??? Fast regular expression grep for source code with incremental index
updates

------
res0nat0r
Any examples or reasons why I should use this over the_silver_searcher?

------
volune
How does this compare with Ack?

------
kumarishan
can it be integrated with sublime text ?

------
wangweij
Examples or it didn't happen.

~~~
invernomut0
e.g. $ cgrep -r --header "stdio.h" to search recursively for headers

$cgrep -r --identifier VARname to search for a variable

etc..

------
WorldWideWayne
It really sucks that 15 languages that people use _less_ than C# are supported
before anyone thinks of adding support for C#.

Why does everyone hate Microsoft's languages and love Apples?

~~~
TallGuyShort
The most reasonable explanation is that this is developed by (an) Apple
user(s) and adding support for Apple's languages is simply easier and more
valuable than adding languages for a platform they don't use. If it's worth it
to you or other C# users, I'm sure they wouldn't mind you submitting a pull
request.

~~~
WorldWideWayne
They actually do support C#, but I missed it because I read the list too
quickly.

