diff --git a/README b/README index e69de29..458c75a 100644 --- a/README +++ b/README @@ -0,0 +1,28 @@ +Sublime Text 2 Plugins +=============================================== + +This is just a handy place to store some plugins I use for ST2. + + +blame.py +======== + +blame.py is a Git blame plugin. It takes selected lines as arguments +and outputs the data into the console. + + +Installation +------------ + +Copy **blame.py** into your ST2 User packages folder *(Sublime Text 2 > +Preferences > Browse Packages... > User)* + +Usage +----- + +Select text or click desired line(s), then context (right) click. +Choose "Blame..." + +I've added this to my User Key Bindings, which works well (Command-Shift-B on a Mac): + + { "keys": ["super+shift+b"], "command": "blame" } diff --git a/blame.py b/blame.py new file mode 100644 index 0000000..1eabed3 --- /dev/null +++ b/blame.py @@ -0,0 +1,18 @@ +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