Last active
August 8, 2022 21:46
-
-
Save silvioprog/c08a7313567f413e6b8eff802a182454 to your computer and use it in GitHub Desktop.
Spell checking for git commit message using aspell(1).
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
#!/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