Sublime Forum

Open Sublime Merge From Sublime Text

#1

Because I use Sublime Text as my main editor, and now I use Sublime Merge as my main Git client, it would be useful to have an option in Sublime Text to open the current project or folder in Sublime Merge.

Another, more dramatic route, would be to integrate Sublime Merge into Sublime Text << I can dream, can’t I?

0 Likes

#2

A possibility is outlined in post 2 of

2 Likes

#3

Thanks, @deathaxe

0 Likes

#4

I have a simple package that opens the current project in merge if it’s a git repo and can also open the history of the current file. It’s quite bare bones but I find it handy.

I’m on mobile at the moment, but if you’re interested when I get home this evening I can share it.

1 Like

#5

Why not? We are super interested!

0 Likes

#6

If you’ve linked or exported into your path the Sublime Text/Merge command line tools, you can add this to your keymap settings in ST:

  { // Open in Sublime Merge
    "keys": ["super+alt+z"],
    "command": "exec",
    "args": {"cmd":  ["smerge", "$project"]}
  },

ST seems smart enough about giving you the correct parent folder when dealing with a project that has multiple root folders under separate git management.

For those not in the know:

0 Likes

Integration with ST
#7

Below is a public gist that contains the code for this simple package. You can either drop the files directly into your User package or create a folder for it in the Packages folder (use Preferences > Browse Packages to find either of those locations) as desired. If you go the User package route, you may want to be sure you don’t accidentally clobber over any menu extension files you might have in there.

As I mentioned above, this is a pretty simple package overall, sort of ripe for future expansion in an alternate universe where I have an infinite amount of free time. Feel free to grab it and augment it or use it as the basis for something cooler (if you do that, drop me a line, that sounds neat :slight_smile:).

This provides two commands, one that opens a repository in Sublime Merge and one that opens the file history for the current file (and also opens the repository in Merge as a requirement).

The command to open the repo in Merge is available from the Command Palette and also in the context menu for folders in the side bar.

The command to open the history for the current file is available from the Command Palette and the context menu for files in the side bar . This opens the repo in merge and immediately enters the search mode focused on the appropriate file. If that file has a non-empty selection, it also adds a search term to see not only the history of that file but the history of the selected lines in that file.

Both commands disable themselves if they think they don’t apply (i.e. no git repo), which for the command palette makes them invisible. This is done by looking for a .git directory (which is done in _find_git_root()). This may or may not need to be modified to find things like worktrees and such (since until people talked about them when Merge was released I had no idea that they existed :wink:).

2 Likes

#8

The newest Dev build has a new command that you can set as a keymap/shortcut directly:

 { // Open in Sublime Merge
    "keys": ["super+alt+z"],
    "command": "sublime_merge_open_repo"
  },
2 Likes

#9

This works but I have to have a specific file open in the repo. It’d be cool if I could have it open my project in Sublime Merge. Thanks for the keymap!

EDIT:
I see your comment above about running the smerge command from a keymap as well - that’ll probably do it.

1 Like

#10

The Dev build also has a new button in the lower corner to open Smerge to the repo the current file belongs to.

0 Likes

#11

It doesn’t seem to work for me on Windows 10 - it does work on my macOS machine though…

0 Likes