-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathspell-check-md-files.hook
47 lines (42 loc) · 1.43 KB
/
spell-check-md-files.hook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
# Based on a hook from tygertec.com
# Source: https://cloudrkt.com/spellcheck-hook.html
#
# Used to check files with the .md extension (markdown) for spelling errors.
# It will run each .md file through aspell and returns an exit code other than 0 when it matches.
#
# Requirements:
# * Bash
#
# To enable this hook, rename this file to "pre-commit".
# 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."
echo -e "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