Skip to content

Instantly share code, notes, and snippets.

@meain
Last active November 22, 2021 05:18
Show Gist options
  • Save meain/163ae5f02974d225c49d25826363e628 to your computer and use it in GitHub Desktop.
Save meain/163ae5f02974d225c49d25826363e628 to your computer and use it in GitHub Desktop.
Check for curse words ( used as git pre-commit hook )
# to use this use
# mv pre-commit .git/hooks/pre-commit
# chmod +x .git/hooks/pre-commit
function check_sanity(){
git diff | grep -i 'fuck\|shit\|crap\|dammit\|bitch\|asshole\|shithead'|wc -m
}
function print_insanity(){
git diff | grep -i 'fuck\|shit\|crap\|dammit\|bitch\|asshole\|shithead'
}
if [ $(check_sanity) -gt 0 ]
then
echo "Curse word found!"
echo ""
echo "$(print_insanity)"
exit 1
fi
@crufter
Copy link

crufter commented Nov 14, 2019

@meain Very cool!

@TexasDex
Copy link

Nice! You may need to change 'git diff' to 'git diff --staged' to ensure you're grepping the changes that will be committed, rather than unstaged changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment