Last active
November 22, 2021 05:18
-
-
Save meain/163ae5f02974d225c49d25826363e628 to your computer and use it in GitHub Desktop.
Check for curse words ( used as git pre-commit hook )
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
# 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 |
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
@meain Very cool!