PageRenderTime 57ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/bin/re-commands

https://bitbucket.org/flowblok/dotfiles
Python | 26 lines | 20 code | 4 blank | 2 comment | 5 complexity | 222968d0961f35baea4acd9b2a3c5e75 MD5 | raw file
Possible License(s): WTFPL
  1. #!/usr/bin/env python
  2. import os
  3. import re
  4. import sys
  5. checks = []
  6. args = iter(sys.argv[1:])
  7. for regex, command in zip(args, args):
  8. checks.append((
  9. re.compile(regex),
  10. command,
  11. ))
  12. while True:
  13. #for line in sys.stdin:
  14. line = sys.stdin.readline()
  15. if not line:
  16. break
  17. line = line[:-1]
  18. for regex, command in checks:
  19. if regex.match(line):
  20. os.system(
  21. regex.sub(command, line)
  22. )