dotfiles/.config/git/hooks/pre-commit
2024-04-10 10:00:52 +02:00

40 lines
1.1 KiB
Bash
Executable file

#!/bin/bash
# -----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <florianbadie@odrling.xyz> wrote this file. As long as you retain this notice
# you can do whatever you want with this stuff. If we meet some day, and you
# think this stuff is worth it, you can buy me a beer in return. odrling
# -----------------------------------------------------------------------------
die() {
echo -e " ${NOCOLOR-\e[1;31m*\e[0m }${*}" >&2
exit 1
}
einfo() {
echo -e " ${NOCOLOR-\e[1;32m*\e[0m }${*}" >&2
}
ewarn() {
echo -e " ${NOCOLOR-\e[1;33m*\e[0m }${*}" >&2
}
runif() {
if [ "$(git config "odrhooks.$1")" = 1 ]; then
shift
einfo "$*"
sh -c "$*" || die "$*: failed"
fi
return 0
}
runif "isort" isort . --check
runif "black" black . --check
runif "ruff" ruff check .
runif "pyright" pyright .
runif "clangformat" 'fd --glob \*.c | xargs clang-format -Werror -n'
runif "gofmt" '[ "$(gofmt -l . | wc -l)" -eq 0 ] || (gofmt -l -d .; exit 1)'
runif "muonfmt" "fd meson.build | xargs muon fmt -q"
runif "muon" "muon analyze"