gg - wrapping git-grep

11 August 2009   0 comments   Linux

Mind That Age!

This blog post is 8 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':

#!/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.

Follow @peterbe on Twitter

Comments

Thank you for posting a comment

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:
Bash tip of the day: ff 25 March 2011
Redirect stderr into becoming dots in Bash 02 September 2006
Ctags in Atom on OSX 26 February 2016
Git + Twitter = Friedcode 22 April 2009
Emacs html-mode for .zpt and .dtml 15 April 2004