Commit 1a46d4aa authored by Thanassis Tsiodras's avatar Thanassis Tsiodras
Browse files


Example repo to test spell checking.
Place the pre-commit file in your .git/hooks and make sure it is executable.
Also, install aspell!
set -e
NC='\033[0m' # No Color
# This script is a Git pre-commit hook that spell checks any content you are
# about to commit.
# Place this script into the ".git/hooks/" directory in your repository.
# It must be called "pre-commit" and be executable. A Git hook only works in a
# single repository. You need to copy this hook into every repository you wish
# to use it in manually. Optionally, you can set up a symlink in the
# ".git/hooks/" directory pointing to the script.
# Each time you try to commit something, this script is run and spell checks
# the content you are committing.
# Should you want to bypass the pre-commit hook (though not recommended), you
# can commit with "git commit --no-verify".
# The temporary dictionary (a binary file) created from the dict
# text file. It is deleted after the script finishes.
temp_dict=$(mktemp /tmp/docs-dictionary-XXXXXX)
# Language of your doc. When using a non-English language, make sure you have
# the appropriate aspell libraries installed: "yum search aspell". For example,
# to spell check in Slovak, you must have the aspell-sk package installed.
# Clean up if script is interrupted or terminated.
trap "cleanup" SIGINT SIGTERM
# Prepares the dictionary from scratch in case new words were added since last time.
function prepare_dictionary() {
if [ 0 -eq $(find . -name *.dict | wc -l) ] ; then
echo "${RED}Failed to find *.dict file in the repo (no custom dictionary)${NC}"
exit 1
temp_file=$(mktemp /tmp/temp_file-XXXXXX)
find . -name *.dict -exec cat '{}' \; | sort -u > "$temp_file"
aspell --lang="$lang" create master "$temp_dict" < "$temp_file"
/bin/rm -f "$temp_file"
# Removes the temporary dictionary.
function cleanup() {
/bin/rm -f "$temp_dict"
# Spell checks content you're about to commit. Writes out words that are
# misspelled or exits with 0 (i.e. continues with commit).
function spell_check() {
find . -name '*.rst' | while read SRC ; do
output=$(cat "$SRC" | aspell list --lang="$lang" --extra-dicts="$temp_dict")
if [[ $? != 0 ]] ; then
echo "${RED}Failed spell check on $SRC...${NC}"
echo "Please check with: aspell -c $SRC"
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 $SRC"
exit 1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment