#!/bin/sh
# Windows doesn't have the 'dirname' command, so fake it
dirname() {
	dir=$(echo "$@" | perl -pe 's,(.*)/[^/]+,\1,')
	test "$dir" = "$1" && dir=.
	echo "$dir"
}

mydir="$(dirname "$0")"
parentdir="$(dirname "$mydir")"

# Windows uses 'git-cola.pyw' instead of 'git-cola'
COLA="$parentdir"/bin/git-cola
if test -f "$COLA".pyw; then
	COLA="$COLA".pyw
fi

# The path to python can be specified by setting the
# PYTHON environment variable.
if test -z "$PYTHON"
then
	PYTHON="$(which python.exe 2>/dev/null)"
fi
# The path to python can be specified in the
# `cola.pythonlocation` git configuration variable.
if test -z "$PYTHON"
then
	PYTHON="$(git config cola.pythonlocation)"
fi
if test -n "$PYTHON"
then
	exec "$PYTHON" "$COLA" "$@"
fi

# Find a suitable Python and use it to run cola.
# If your python is installed in another location then
# add that path to the top of the list below or
# set the `cola.pythonlocation` git configuration variable.
for python in \
	"/c/Python312" \
	"/c/Python311" \
	"/c/Python310" \
	"/c/Python39" \
	"/c/Python38" \
	"/c/Python37" \
	"/c/Python36" \
	"/c/Python35" \
	"/c/Python34"
do
	if test -d "$python"
	then
		PATH="$python":"$PATH" exec "$python/python.exe" "$COLA" "$@"
	fi
done
exit 1
