Rewrite of greenbar
Blogger wouldn't format this right, so I'm putting my response here.
Here's a version using the file iterator capabilities on stdin, enumerate for the line number, all the logic combined into one if-statement, and a different strategy for printing the highlights.
#!/usr/bin/python -u
import sys
try:
pat = sys.argv[1]
except IndexError:
pat = None
for lineno, line in enumerate(sys.stdin):
if (pat and pat in line) or (not pat and lineno % 2 == 0):
print "\x1b[7m%s\x1b[0m" % line.rstrip()
else:
print line,
- New comment
Atom feed of this blog