cfg/bin/git-autohook
Knut Ahlers aac696fafb
Add support for hooks in Justfile and Makefile
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2021-12-31 21:58:26 +01:00

18 lines
506 B
Bash
Executable file

#!/bin/bash
HOOKTYPE=$1
if [ -e Justfile ]; then
just --list --list-heading '' --list-prefix '' |
grep -q "auto-hook-${HOOKTYPE}" && exec just "auto-hook-${HOOKTYPE}" || true
fi
if [ -e Makefile ]; then
TARGETS=$(make -pRrq : 2>/dev/null |
awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' |
sort | egrep -v -e '^[^[:alnum:]]' | sed 's/:$//' | xargs)
if (echo $TARGETS | grep -q "auto-hook-${HOOKTYPE}"); then
exec make "auto-hook-${HOOKTYPE}"
fi
fi