How to auto-configure git merge tool based on what is available on current machine?

I am working a many system and at least on some of them my home directory is stored on NIS, so I do share that same preferences.

I do want to write a small bash script which I can include inside ~/.bash_profile which will configure the best diff tool which is already installed on current machine.

The rule is simple, I have to check which command line diff tools are available and configure git to use the first one that I found.

Side note: On one linux machine I discovered that there is and ENV variable __git_mergetools_common=$'diffuse ecmerge emerge kdiff3 meld opendiff\n\t\t\ttkdiff vimdiff gvimdiff xxdiff araxis p4merge\n' – I have no idea what is this used for, but it looks interesting.

Git Baby is a git and github fan, let's start git clone.