dakrauth
12/16/2011 - 2:45 PM

TextMate command to align on colons

TextMate command to align on colons

#!/usr/bin/env python
import os
bits = [line.split(':', 1) for line in os.environ['TM_SELECTED_TEXT'].splitlines()]
width = 1 + max([len(bit[0]) for bit in bits if len(bit) == 2])
for bit in bits:
    if len(bit) == 2:
        print '%-*s %s' % (width, bit[0] + ':', bit[1].strip())
    else:
        print bit[0]