Skip to content

Instantly share code, notes, and snippets.

@silvioprog
Last active August 8, 2022 21:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silvioprog/c08a7313567f413e6b8eff802a182454 to your computer and use it in GitHub Desktop.
Save silvioprog/c08a7313567f413e6b8eff802a182454 to your computer and use it in GitHub Desktop.
Spell checking for git commit message using aspell(1).
#!/bin/sh
#
# This file is distributed under Public domain.
#
# Author: silvioprog.
#
# Installing:
#
# - `$ mv commit-msg.sh .git/hooks/commit-msg`
# - `$ chmod +x .git/hooks/commit-msg`
#
# Now, if you need to change the language code (default:en_US) and/or
# the encoding (default:utf-8), customize the variables `LANG` and
# `ENCODING` below.
#
# Feel free to use or improve it and have a lot of fun! (:
# Language code, e.g.: "pt_BR"
LANG="en_US"
# Encoding to expect data to be in.
ENCODING="utf-8"
aspell="$(which aspell 2>/dev/null)"
if [ $? -ne 0 ]; then
echo "error: aspell is not installed. See 'http://aspell.net'." >&2
exit 1
fi
words=$($aspell --encoding=$ENCODING --lang=$LANG --list < "$1")
msg=$(cat "$1")
if [ -n "$words" ]; then
echo "warning: possible spelling errors:" >&2
echo "" >&2
echo "$words" >&2
echo "" >&2
echo "correct the message or skip this warning with" >&2
echo " git commit --no-verify -m \"$msg\"" >&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment