Last active
August 29, 2022 09:57
-
-
Save sonOfRa/569b7b04cb280c07853fee8363e0782f to your computer and use it in GitHub Desktop.
Use Sublime Merge as a git mergetool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[merge] | |
tool = sublime_merge | |
[mergetool] | |
keepBackup = false | |
[mergetool "sublime_merge"] | |
trustExitCode = false | |
cmd = "/path/to/mergetoolwrapper.sh" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not perfect, but it works.
Caveats:
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 scriptIf, for some reason, your repository path contains, but does not start with your home directory, this will probably not work.Fixedgit mergetool