Last active
December 20, 2023 08:26
-
-
Save cloudrkt/e680a0270478a58f25c3c7fe32710423 to your computer and use it in GitHub Desktop.
Spellcheck pre-commit hook
This file contains 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
#!/usr/bin/env bash | |
# This script is used to check files with the .md extention (markdown) for spelling errors. | |
# It will run each .md file through aspell and returns an exit code other then 0 when it matches. | |
# Where are the markdown files located? | |
SEARCH_DIR="content" | |
# Set some fancy colors to indicate errors and wrongly spelled words. | |
RED='\033[0;31m' | |
YELLOW='\033[0;33m' | |
NC='\033[0m' # No Color | |
# Start checking the current directory for md files | |
for file in $(find $SEARCH_DIR -type f -name "*.md"); | |
# Pass each .md file through aspell. | |
do output=$(cat $file | aspell --lang=en list); | |
if [[ $? != 0 ]]; then | |
echo -e "${RED}Error found in output${NC}, cannot continue. Please check manually for aspell -c $file?" | |
exit 1 | |
elif [[ $output ]]; then | |
echo -e "-> ${RED}Spelling errors found${NC} <-" | |
echo -e "${YELLOW}$output${NC}" |sort -u | |
echo "Please check with: aspell -c $file" | |
bad="yes" | |
good="yes" | |
fi | |
done | |
# Matched in aspell | |
if [[ "$bad" == "yes" ]]; then | |
exit 1 | |
fi | |
# No match in aspell | |
if [[ "$good" == "yes" ]]; then | |
echo -e "Spelling check is ${RED}OK${NC}, good to go." | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment