Skip to content

Instantly share code, notes, and snippets.

@silvioprog

silvioprog/commit-msg.sh

Last active Sep 5, 2019
Embed
What would you like to do?
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