Home Download Buy Blog Forum Support

Git blame current selection

Git blame current selection

Postby ehamiter on Wed May 25, 2011 5:22 am

I wanted an easy way to be able to select a line or two (or twenty) and see the last revision's author and time of change. This will pop open the console and write to it:

Image

Here's the code for "blame.py":

Code: Select all
import os
import sublime
import sublime_plugin

class BlameCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        if len(self.view.file_name()) > 0: 
            folder_name, file_name = os.path.split(self.view.file_name())
            begin_line, begin_column = self.view.rowcol(self.view.sel()[0].begin())
            end_line, end_column = self.view.rowcol(self.view.sel()[0].end())
            begin_line = str(begin_line)
            end_line = str(end_line)
            lines = begin_line + ',' + end_line
            self.view.window().run_command('exec', {'cmd': ['git', 'blame', '-L', lines, file_name], 'working_dir': folder_name})         
            sublime.status_message("git blame -L " + lines + " " + file_name)

    def is_enabled(self):
        return self.view.file_name() and len(self.view.file_name()) > 0


I threw it on github here as well:
https://github.com/ehamiter/Sublime-Text-2-Plugins
ehamiter
 
Posts: 67
Joined: Wed Apr 27, 2011 2:42 am

Re: Git blame current selection

Postby rdougan on Thu Jun 02, 2011 9:58 pm

Nice, thanks.
rdougan
 
Posts: 44
Joined: Sat Apr 09, 2011 2:37 am


Return to Plugin Announcements

Who is online

Users browsing this forum: Exabot [Bot], randy3k, Yahoo [Bot] and 5 guests