mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-22 15:56:18 +00:00
feat(bin): update scripts to function format
This commit is contained in:
@@ -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 "$@"
|
||||
|
||||
Reference in New Issue
Block a user