Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
# encoding: utf-8
import sys
import os
from optparse import OptionParser,OptionGroup
from pygments import highlight
from pygments.lexers import DiffLexer
from pygments.formatters import HtmlFormatter
from subprocess import Popen, call, STDOUT, PIPE
html_shell = """
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>hg diff</title>
<meta name="generator" content="TextMate">
<meta name="author" content="Preston Holmes">
<!-- Date: 2009-11-20 -->
<style type="text/css" media="screen">
def sh(cmd):
return Popen(cmd,shell=True,stdout=PIPE,stderr=PIPE).communicate()[0]
def main(argv=None):
parser = OptionParser()
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
help="display all verbose output",default=False)
# parse options: metavar, default action: store
parser.usage = """
help message
(options, args) = parser.parse_args()
file_to_diff = os.path.abspath(args[0])
diff_str = sh ('hg diff "%s"' % file_to_diff)
css = HtmlFormatter().get_style_defs()
html = highlight(diff_str, DiffLexer(), HtmlFormatter())
s = html_shell % (css,html)
sh ('open -a safari /tmp/diff.html')
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment