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.

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':

#!/usr/bin/python
import sys, os
args = sys.argv[1:]
i = False
if '-i' in args:
    i = True
    args.remove('-i')
pattern = args[-1]
extra_args = ''
if len(args) > 1:
    extra_args = ' '.join(args[:-1])
if i:
    param = "-in"
else:
    param = "-n"
cmd = "git grep %s %s '%s'" % (param, extra_args, pattern)
os.system(cmd)

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
Homesite.py:526:    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
(END) 

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.

Comments

Your email will never ever be published


Related posts

Previous:
Public calendars on Google Calendar 08 August 2009
Next:
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:
Be very careful with your add_header in Nginx! You might make your site insecure 11 February 2018
jQuery and Highslide JS 08 January 2008
I'm back! Peterbe.com has been renewed 05 June 2005
Anti-McCain propaganda videos 12 August 2008
I'm Prolog 01 May 2007