#!/usr/bin/env sh
# shellcheck disable=SC1090
[ "$HUSKY" = "2" ] && set -x
h="${0##*/}"
s="${0%/*/*}/$h"

[ ! -f "$s" ] && exit 0

for f in "${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh" "$HOME/.huskyrc"; do
	[ -f "$f" ] && . "$f"
done
[ "${HUSKY-}" = "0" ] && exit 0

f=$([ "$h" = "pre-commit" ] && git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g')
x() {
	[ -z "$f" ] && return
	g=$(echo "$f" | grep "$1")
	echo "$g" | xargs "$2"
	echo "$g" | xargs git add
}

c=0
h() {
	[ $c != 0 ] && echo "husky - $h script failed (code $c)"
	[ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
	exit 1
}
trap 'c=$?; h' EXIT
set -e
PATH=node_modules/.bin:$PATH
. "$s"