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

@@ -6,18 +6,46 @@
# Copyright 2023 Ismo Vuorinen. All Rights Reserved.
# License: MIT <https://opensource.org/license/mit/>
STARTING_PATH=${1:-$(pwd)}
set -euo pipefail
DIRS=$(find "$STARTING_PATH" -mindepth 1 -maxdepth 1 -type d)
# Enable verbosity with VERBOSE=1
VERBOSE="${VERBOSE:-0}"
for DIR in $DIRS; do
echo "-> Processing dir: $DIR"
cd "$DIR" || exit 1
if [ -d "$DIR/.git" ]; then
git fsck --no-dangling --full --no-progress
echo ""
fi
done
# Function to print messages if VERBOSE is enabled
# $1 - message (string)
msg()
{
[ "$VERBOSE" -eq 1 ] && echo "$1"
}
echo ""
echo "Done."
# Function to perform git fsck on a repository
# $1 - directory (string)
fsck_repo()
{
local dir=$1
msg "Processing dir: $dir"
(
cd "$dir" || exit 1
if [ -d ".git" ]; then
git fsck --no-dangling --full --no-progress
echo ""
fi
)
}
# Main function
main()
{
local starting_path=${1:-$(pwd)}
local dirs
dirs=$(find "$starting_path" -mindepth 1 -maxdepth 1 -type d)
for dir in $dirs; do
fsck_repo "$dir"
done
echo ""
echo "Done."
}
main "$@"