added grep command

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-07-08 23:46:59 +00:00
parent c35e72d6fc
commit 95f63f3ca2
1 changed files with 27 additions and 0 deletions

View File

@ -1398,3 +1398,30 @@ class RegisterRestore(Method):
if len(name) > self.MAX_REG: if len(name) > self.MAX_REG:
name = name[0:self.MAX_REG] + '...' name = name[0:self.MAX_REG] + '...'
w.set_error('Restored %r from register %r' % (text2, name2)) w.set_error('Restored %r from register %r' % (text2, name2))
class Grep(Method):
'''help here'''
args = [Argument('pattern', datatype="str", prompt="Pattern: ")]
def _execute(self, w, **vargs):
cmd = ("/usr/bin/grep", '-E', '-n', vargs['pattern'], '-')
pipe = popen2.Popen3(cmd, capturestderr=True)
pid = pipe.pid
indata = w.buffer.make_string()
pipe.tochild.write(indata)
pipe.tochild.close()
outdata = pipe.fromchild.read()
errdata = pipe.childerr.read()
status = pipe.wait() >> 8
if status == 0:
num = len(outdata.split('\n'))
w.application.data_buffer("*Grep*", outdata, switch_to=True)
w.application.set_error("Grep: %d matches found" % num)
elif status == 1:
w.application.set_error("Grep: no matches found")
else:
w.application.data_buffer("*Grep*", outdata, switch_to=True)
w.set_error("Grep: error (exited with status %d)" % status)