Skip to content

Instantly share code, notes, and snippets.

@mattfoster
Created December 14, 2008 11:23
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 mattfoster/35668 to your computer and use it in GitHub Desktop.
Save mattfoster/35668 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Add comments to the end of lines
# Set `save` to `nothing`
# Set `input` to `selected text` or `line`
# Set `output` to `replace selected text`
import sys, os
comment_char = os.environ.get('TM_COMMENT_START', '#')
default_column = 55 # could set TM_DEFAULT_COMMENT_COL or similar
lines = sys.stdin.readlines()
lens = [len(s) for s in lines]
max_len = max([max(lens), default_column])
for line in lines:
print "%-*s %s" % (max_len, line.rstrip('\n').rstrip(), comment_char)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment