Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Tags: Python,GitWho,run, Created At: 10/24/2016 8:08:45 PMViews:

HTML view:
Copy Source | Copy HTML
  1. import sublime, sublime_plugin
  2. import os, re
  3. class GitWho(sublime_plugin.TextCommand):
  4.     def run(self, edit):
  5.         v = self.view
  6.         file_name = v.file_name()
  7.         line, col = v.rowcol(v.sel()[ 0].begin())
  8.         line += 1
  9.         cwd = os.getcwd() # save current work directory...
  10.         os.chdir(os.path.dirname(file_name)) # ... to use git ...
  11.         output = os.popen("git blame -L " + str(line) + "," + str(line) + " " + file_name).read()
  12.         os.chdir(cwd) # ... and reset it back
  13.         tmp = re.search('\((.*) (\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2} [+-]\d{4})', output)
  14.         if tmp:
  15.             author, date, time = tmp.group(1), tmp.group(2), tmp.group(3)
  16.             sublime.status_message('Changed by ' + author + ' on ' + date + ' at ' + time)
  17.         else:
  18.             sublime.status_message('Cannot blame this file')

Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2018