gg - wrapping git-grep

11 August 2009   0 comments   Linux

Powered by Fusion×

I've grown quite addicted to this and finding that it's saving me tonnes of milliseconds every day. First of all, I've made this little script and put it in my bin directory called '~/bin/gg':

import sys, os
args = sys.argv[1:]
i = False
if '-i' in args:
    i = True
pattern = args[-1]
extra_args = ''
if len(args) > 1:
    extra_args = ' '.join(args[:-1])
if i:
    param = "-in"
    param = "-n"
cmd = "git grep %s %s '%s'" % (param, extra_args, pattern)

Basically, it's just a lazy short hand for git grep ("Look for specified patterns in the working tree files"). Now I can do this:

peterbe@trillian:~/MoneyVillage2 $ gg getDIYPackURL    def getDIYPackURL(self):
zpt/homepage/index_html.zpt:78:       tal:attributes="href here/getDIYPackURL">Get your free trial here</
zpt/moneyconcerns/index_html.zpt:36:       tal:attributes="href here/getDIYPackURL">Get your free trial h
zpt/moneyconcerns/index_html.zpt:50:          <p><a tal:attributes="href here/getDIYPackURL" class="makea

It's not much faster than normal grep but it automatically filters out junk. Obviously doesn't help you when searching in files you haven't added yet.


Your email will never ever be published

Related posts

Public calendars on Google Calendar 08 August 2009
Google Reverse Geocoding vs. GeoNames 17 August 2009
Related by keywords:
Git + Twitter = Friedcode 22 April 2009
Bash tip of the day: ff 25 March 2011
Find print statements in Python code 12 April 2005
Grep results expanded 23 April 2005
Redirect stderr into becoming dots in Bash 02 September 2006
Grep in Jed 27 January 2004