Created
June 17, 2024 22:36
-
-
Save igoravl/fb246d54b2a85a3da4921a67900be6cc to your computer and use it in GitHub Desktop.
Pre-commit hook to require UTF-8 BOM encoding in PowerShell scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Função para verificar BOM UTF-8 | |
check_bom() { | |
local file=$1 | |
if [[ $(head -c 3 "$file") == $'\xEF\xBB\xBF' ]]; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
# Lista de arquivos .ps1 a serem validados | |
files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.ps1$') | |
# Se não houver arquivos .ps1, saia | |
if [ -z "$files" ]; then | |
exit 0 | |
fi | |
# Verificar cada arquivo .ps1 | |
for file in $files; do | |
if ! check_bom "$file"; then | |
echo "Error: file '$file' is not encoded as UTF-8 BOM." | |
exit 1 | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment