#! /usr/bin/python

import os, re, string, sys


conffilename = [os.environ['HOME']+"/.grc/grc.conf", "/etc/grc.conf"]
for i in conffilename:
	if os.path.isfile(i):
		conffile = i
		break
regexplist = []

f = open(conffile, "r")
while 1:
	l = f.readline()
	if l == "" :
		break
	if l[0] == "#" or l[0] == '\012':
		continue
	regexp = l[:-1]
	cfile = f.readline()[:-1]
	if re.search(regexp, string.join(sys.argv[1:])):
		os.system(string.join(sys.argv[1:]) + " | grcat " + cfile)
		sys.exit()

os.system(string.join(sys.argv[1:]))

