11 August 2009 0 comments Linux
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.