git or Versions.app with MacVim diff

03/05/2010

I've seen on the Versions Google group, there's a python script for integrating Versions with MacVim diff, but because Versions doesn't appear to be completely contextual when it comes to executing the script, I was getting the GUI load with none of my .vimrc stuff, so it was no good really.

I tried to write a PHP script to do this, as that's what I'm most familiar with, but I also hit this hurdle so it was time to dust off my (formerly almost nonexistant) bash knowledge to try and get this done properly. I believe I've come up with a fix.

When writing this, I came across two problems. One being that Versions doesn't escape space characters in the arguments is passes to your script, so it's not just a simple case of export HOME="/your/home"; mvim -d $@; that gives you at least 3 files to play with, so I've /tried/ to be a bit clever and parse what I think is a file into an array and use it as arguments. It's not terribly elegant, but it works and I've been using it a couple of days.

The only issue is that you'll have to change the path to your home directory in the script, because I don't know of a way to detect it. If there is one, please let me know!

Download the attached zip, chmod +x and put it in your ~/Library/Application Support/Versions/Compare Scripts/ folder, restart Versions, then you should see it as an option in your File Comparison dropdown.

To use this with git, I kept the file the same, and then git config --global diff.tool /Users/Me/Library/Application Support/Versions/Compare Scripts/mvimd.sh and it works great with that too. Go me.