gg - wrapping git-grep

11 August 2009   0 comments   Linux

Mind That Age!

This blog post is 9 years old! Most likely, its content is outdated. Especially if it's technical.

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.


Thank you for posting a comment

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 Keyword:
A neat trick to zip a git repo with a version number 01 September 2017
gg - A prototype to rule Git, GitHub and Bugzilla 06 May 2016
.git/info/exclude, .gitignore and ~/.gitignore_global 20 April 2016
How I git 18 June 2015
Bash tip of the day: ff 25 March 2011
Related by Text:
Bash tip of the day: ff 25 March 2011
Ctags in Atom on OSX 26 February 2016
Redirect stderr into becoming dots in Bash 02 September 2006
Git + Twitter = Friedcode 22 April 2009
jsonpprint - a Python script to format JSON data nicely 21 November 2010