Skip to content

Instantly share code, notes, and snippets.

@sonOfRa
Last active August 29, 2022 09:57
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sonOfRa/569b7b04cb280c07853fee8363e0782f to your computer and use it in GitHub Desktop.
Save sonOfRa/569b7b04cb280c07853fee8363e0782f to your computer and use it in GitHub Desktop.
Use Sublime Merge as a git mergetool
#!/bin/bash
# A wrapper script to make sublime_merge work more nicely
# when used as a git-mergetool
WORKDIR=`git rev-parse --show-toplevel`
REAL_HOME="$HOME/"
# Replace a leading homedir with ~/ to match the window title
REAL_WORKDIR=${WORKDIR/"^$REAL_HOME"/"~/"}
sublime_merge $REAL_WORKDIR
# Wait here for safety, no idea how long launching
# and daemonizing can take
sleep 2
# List all the windows first
# Then look for all Sublime Merge windows
# Then check if there is one for our current work dir
while wmctrl -lx | grep "sublime_merge.Sublime_merge" | grep -q "$REAL_WORKDIR"; do sleep 1; done
exit 0
[merge]
tool = sublime_merge
[mergetool]
keepBackup = false
[mergetool "sublime_merge"]
trustExitCode = false
cmd = "/path/to/mergetoolwrapper.sh"
@sonOfRa
Copy link
Author

sonOfRa commented Sep 24, 2018

It's not perfect, but it works.

Caveats:

  • I do not know how this interacts with git rerere
  • Sublime Merge "exits" on the command line before the editor is closed, so git will ask if the merge is satisfactory immediately (do not answer yes before merging) fixed by the wrapper script
  • If, for some reason, your repository path contains, but does not start with your home directory, this will probably not work. Fixed
  • Only works on window managers that are compatible with wmctrl (I only tested GNOME)
  • May not work if you have the window for this specific repository already open when invoking git mergetool

@michaelblyons
Copy link

Note that smerge itself is beginning to become a git mergetool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment