feat(bin): update scripts to function format

This commit is contained in:
2024-07-23 03:45:22 +03:00
parent 4e4692321b
commit 26f6024292
23 changed files with 1038 additions and 414 deletions

View File

@@ -1,19 +1,41 @@
#!/usr/bin/env bash
#
# Check git repo's files .gitattributes and are all of them mapped.
# Check git repo's files .gitattributes and ensure all of them are mapped.
# Ismo Vuorinen <https://github.com/ivuorinen> 2022
#
source "${DOTFILES}/config/shared.sh"
if ! command -v git &> /dev/null; then
echo "git could not be found, please install it first"
exit 1
fi
set -euo pipefail
missing_attributes=$(git ls-files | git check-attr -a --stdin | grep "text: auto")
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
if [[ "$missing_attributes" ]]; then
echo ".gitattributes rule missing for the following files:"
echo "$missing_attributes"
else
echo "All files have a corresponding rule in .gitattributes"
fi
# Function to check if git is installed
check_git_installed()
{
if ! command -v git &> /dev/null; then
msg_err "git could not be found, please install it first"
fi
}
# Function to check for missing .gitattributes
check_gitattributes()
{
local missing_attributes
missing_attributes=$(git ls-files | git check-attr -a --stdin | grep "text: auto" || true)
if [[ -n "$missing_attributes" ]]; then
echo ".gitattributes rule missing for the following files:"
echo "$missing_attributes"
else
echo "All files have a corresponding rule in .gitattributes"
fi
}
# Main function
main()
{
check_git_installed
check_gitattributes
}
main "$@"