How can I make SnailSvn use vimdiff or any custom diff script? It only has a predefined list of options.

To setup its diff support (for opendiff aka FileMerge), it asks you to copy the following script to: ~/Library/Application Scripts/net.langui.SnailSVN.DiffTool/difftool.sh

pkill -nf ScriptMonitor
sh "$@"

The argument is a generated diff-cmd.sh file that looks something like this:

"/Applications/Xcode.app/Contents/Developer/usr/bin/opendiff" "/var/folders/nn/000000000000000000000000000000/T/net.langui.SnailSVNFree//r422640 Code.cs" "/Users/idbrii/code/game/Assets/Standard Assets/Unlit/Planes/Code.cs"

I tried to replace it with something like:

args=$(grep opendiff "$@" | cut -d\  -f2-)
echo mvimdiff $args >> ~/snailsvndifftool.log 2>&1

But instead I get too many files -- despite files containing quotes, they're still split up by spaces.


With the help of this answer, I found eval:

args=$(grep opendiff "$@" | sed -e 's,"/Applications/Xcode.app/Contents/Developer/usr/bin/opendiff",/usr/local/bin/mvimdiff,')
echo diff: $args >> ~/snailsvndifftool.log 2>&1
# What's this shady thing?
eval       $args >> ~/snailsvndifftool.log 2>&1

However, doing eval on arbitrary arguments seems unnecessarily insecure and I couldn't get arrays to work (i.e., mvimdiff ${args[@]}), so instead I force mvimdiff to be at the beginning of the line and only allow a set of characters:


args=$(grep opendiff "$@" | sed -E 's,"/Applications/Xcode.app/Contents/Developer/usr/bin/opendiff",,; s/[^A-Za-z0-9.~/"_ -]//g; s,^,/usr/local/bin/mvimdiff,')
echo diff: $args >> ~/snailsvndifftool.log 2>&1
eval $args >> ~/snailsvndifftool.log 2>&1

There's probably something I'm missing, so I hope someone has a better answer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .