+# Potential names for clang-format (debian...)
+CLANG_FMT_PNAMES=(clang-format clang-format-5.0 clang-format-4.0 clang-format-3.9 clang-format-3.8)
+CLANG_FMT_CMD="NOT-FOUND"
+GIT_CLANG_FMT_CMD="NOT-FOUND"
+
+# Find which clang-format should be used
+for name in ${CLANG_FMT_PNAMES[*]}
+do
+ where=$(which ${name} 2> /dev/null)
+ if [ x != "x${where}" ]
+ then
+ echo "clang-format found: ${where}"
+ CLANG_FMT_CMD=${where}
+ break
+ fi
+done
+
+if [[ "${CLANG_FMT_CMD}" == NOT-FOUND ]]
+then
+ echo "Unable to find clang-format! Please install it:"
+ echo "- debian(-like): apt-get install clang-format[-VERSION]"
+ echo "- arch(-like): pacman -S clang"
+ echo "- ..."
+ exit 1
+fi
+
+# Find which git-clang-format should be used
+for name in ${CLANG_FMT_PNAMES[*]}
+do
+ where=$(which "git-${name}" 2> /dev/null)
+ if [ x != "x${where}" ]
+ then
+ echo "git-clang-format found: ${where}"
+ GIT_CLANG_FMT_CMD=${where}
+ break
+ fi
+done
+
+if [[ "${GIT_CLANG_FMT_CMD}" == NOT-FOUND ]]
+then
+ echo "Unable to find git-clang-format! Please install it:"
+ echo "- debian(-like): apt-get install clang-format[-VERSION]"
+ echo "- arch(-like): pacman -S clang"
+ echo "- ..."
+ exit 1
+fi
+
+# error on unset variable expansion
+set -u
+# exit on error
+set -e
+