Skip to content

Instantly share code, notes, and snippets.

@gfixler
Created August 26, 2012 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfixler/3478442 to your computer and use it in GitHub Desktop.
Save gfixler/3478442 to your computer and use it in GitHub Desktop.
Simple SVN blame temporal grayscale colorization
#!/usr/bin/env python
'''
SVN blame temporal colorizer
Pipe shell output of `svn blame` through this.
Creates a grayscale heatmap of recentness of line changes.
Normalizes range of revisions over 20 shades of gray.
Usage:
# colorize file
svn blame file | python blamecol.py
# view entire file more easily
svn blame file | python blamecol.py | more
# colorize part of file
svn blame file | tail -n 50 | python blamecol.py
'''
import sys
lines = sys.stdin.readlines()
low = None
high = None
for line in lines:
rev = float(line.split()[0])
if low == None or rev < low: low = rev
if high == None or rev > high: high = rev
for line in lines:
rev = float(line.split()[0])
color = int(round((rev - low) / (high - low) * 20 + 235))
print '\x1b[38;5;%dm%s\x1b[0m' % (color, line),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment