If anyone else comes across this and isn't in whatever college class the original poster was talking about, here's how I solved the problem:
#!/bin/bash
ASPELL=$(which aspell)
if [ $? -ne 0 ]; then
echo "Aspell not installed - unable to check spelling" >&2
exit
else
WORDS=$($ASPELL --mode=email --add-email-quote='#' list < "$1")
fi
if [ -n "$WORDS" ]; then
printf "\e[1;33m Possible spelling errors found in commit message.\n Possible mispelled words: \n\e[0m\e[0;31m%s\n\e[0m\e[1;33m Use git commit --amend to change the message.\e[0m\n\n" "$WORDS" >&2
fi
The key part being --mode=email --add-email-quote='#'
arguments when we actually call aspell
.
--mode
sets the filter mode, and in our case we're setting it to email
mode. Which is described as:
The email
filter mode skips over quoted text. ... The option add|rem-email-quote
controls the characters that are considered quote characters, the defaults are '>
' and '|
'.
So, if we add '#
' to that list of "quote" characters, aspell
will skip over it. We do that of course with the --add-email-quote
option.
Note that we're also skipping over '>
' and '|
', per the documentation. If you don't want aspell
to skip over these, use the --rem-email-quote
option.
See aspell's man page here for more info.