I have tried many things, but none of them worked.

Expected result: I type a shortkey, and git gui blame opens the current file at the line the pointer is on.

I work on Windows 7, with Sublime 3 Build 3083

First try : Custom Build System

{ "cmd": [ "C:\\Program Files (x86)\\Git\\cmd\\git.exe" "gui" "blame" "$file"] }

In a file named git_gui_blame.sublime-build

Then Tools -> Build System -> git_gui_blame. But then Ctrl+B only makes "no build system" appear image showing the error

Second try : Custom key binding

Preference -> Key Bindings - User

{ "keys": ["ctrl+B"],
  "command": "exec", 
  "args": { 
            "cmd": [
                "C:\\Program Files (x86)\\Git\\cmd\\git.exe",
                ?//What to put here ?

I tried replacing "?" with "$file", inspired from the $file of the build system, but I got this error incorrect_file_path

which can be translated by "Incorrect file path : /path/to/$file : Inexistant file or repertory

Third try : Custom Plugin

import sublime, sublime_plugin, os

class SublimeBlameCommand(sublime_plugin.WindowCommand):
def run(self, **kwargs):
    folder_name, file_name = os.path.split(self.window.active_view().file_name())
    print(folder_name + " _______ " + file_name)
        self.window.active_view().run_command('exec', {'cmd': ['C:\\Program Files (x86)\\Git\\cmd\\git.exe', 'gui', 'blame', file_name], 'working_dir':folder_name, 'shell':False} )
    except TypeError:
        print("Error in SublimeBlame Plugin")

and after that, in Preferences -> Key Bindings - User

  { "keys": ["ctrl+k"], 
  "command": "sublime_blame"

But Ctrl+k does absolutely nothing.

So I'm stuck here. What can I do differently ? My prefered try is the second because I feel I got the closest to the expected result, but I couldn't find what to replace the "?" with.


Got it working with:

import sublime, sublime_plugin, subprocess, os, ntpath

class GitguiblameCommand(sublime_plugin.TextCommand):    def run(self,
    if os.name == "nt":
        startupinfo = subprocess.STARTUPINFO()
        startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

    filepath = self.view.file_name()
    dirpath = os.path.dirname(filepath)
    filename = ntpath.basename(filepath)
    process = subprocess.Popen(('C:\Program Files (x86)\Git\cmd\git.cmd', 'gui', 'blame', filename),cwd=os.path.dirname(filepath),
    stdin=subprocess.PIPE, stdout=subprocess.PIPE, startupinfo=startupinfo)

It seems git-gui appends filename to currentworking directory. Use os.path.split or os.path.basename on other OS's.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.