Sublime Forum

Execute external tool from SublimeMerge


Hi all,

I’ve tried out SublimeMerge recently but my workflow requires to call an external tool on a (changed) file, ideally via the File Menu (see screenshot). I’ve tried to add a menu entry via File.sublime-menu which worked, but there doesn’t seem to be an “exec” command or similar available. So basically I have the button but it seems I can only map built-in commands to it?


Is there a possibilty to call an external command (a python script in this case, but could also be a .exe file) from the file menu I’am not aware of, and if not, is this a planned feature for the future?

Thanks in advance and best regards



I believe that the lack of the exec command is due to the fact that Merge doesn’t support plugins yet (although it is on the roadmap) and the exec command from Sublime is defined in a plugin. I don’t think Merge has the ability to execute arbitrary programs directly, but you can use it to execute git commands, and you can set up arbitrary git aliases to do pretty much whatever you want, so that might help you out.

For example, I created /home/tmartin/ with the following content and made it executable:

#!/bin/env python3

import sys

print("I'm a python script running for '%s'" % sys.argv[1])

I then set up an alias named script to invoke it in my git config:

    script = "!f() { /home/tmartin/ $1; }; f"

I then set up a File.sublime-menu file in my merge User package like so:

    { "caption": "-" },
        "caption": "Run my script",
        "command": "git", "args": {
            "argv": ["script", "$path"]

This uses the internal git command to execute git with any arguments you provide, which here are the alias script and also the path of the current file.

So now the command is in the menu:


After picking the command, you can click the Show Git Output button in the header (to the left of the branch name) to see what it did:


I’ve never done anything like this on Windows or MacOS, but I would imagine that git should support aliases for them in the same way.


[Sublime Merge]Hope for multi-user feature

Interesting approach, didn’t cross my mind to use a git alias for that. I was able to reproduce it (Win10) and it works, I think I’ll go with that solution until there is a ‘proper’ exec implemented.
It’s also nice that GUI apps seem to work with the git alias, I tried with calc.exe for now.

Background is that I have to use an ancient version control system (ClearCase) with a graphical version tree that is sadly necessary in a lot of cases. My git repository lays on top of that ClearCase repo, but from time to time I have to interact with it. Being able to do so directly from SublimeMerge is a great help, though.

Also, I’ve looked into SublimeText and found the python file that implements the exec there. Just out of curiosity, are SublimeMerge and SublimeEdit similar enough under the hood to have a chance to get the SublimeText exec working without modifications in SublimeMerge?

Best regards



The two share a lot of the same code base under the hood to a degree (only the Devs know how much though) but Merge doesn’t yet have the ability to be augmented via plugins.

For example, Merge has the ability to allow you to provide arguments to commands via the Command Palette by entering them manually (like tag names) or by selecting from a list of options (like choosing which remote to push to). It appeared in Development builds of Sublime Text first because it was developed for Merge (which was not yet announced).

Plugin support is on the roadmap as something that will probably happen, but I haven’t seen anything in the way of what the API could/would/should look like to be able to extend it. The Text version of exec assumes the existence of output panels to be able to show you the output, which doesn’t directly extend to Merge.

On the other hand, Merge does have some ability to display output as seen above and the code that’s responsible for executing a subprocess is just pure Python, so I would guess that in theory something like this would be possible, though it may require some modifications.



Makes sense, especially this early in development. In some parts of the interface the similarities are quite obvious, but the lack of any *.py files inside the installed default package are a strong indicator that support for plugins is missing atm. However, having a plugin system similar to SublimeText would be a killer feature that’ll set SublimeMerge apart from the other git guis. SourceTree has this “External Command”-feature, but it is really inflexible and didn’t work too well in my case.

Anyway, the solution you suggested works really well for me. Thank you very much for taking the time to write it down in such detail, this made reproducing it really easy :+1: