Skip to content

Instantly share code, notes, and snippets.

@pmoranga
Forked from skwashd/pre-commit
Last active February 28, 2024 11:14
Show Gist options
  • Save pmoranga/c6997d08fa1e7b51625bf532ca1c603e to your computer and use it in GitHub Desktop.
Save pmoranga/c6997d08fa1e7b51625bf532ca1c603e to your computer and use it in GitHub Desktop.
Git pre-commit hook that blocks commits for files that contain swear words.
#!/bin/bash -e
#
# Git pre-commit hook that blocks commits for files that contain swear words.
#
# Created by Dave Hall - http://davehall.com.au
# Distributed under the terms of the WTFPL - http://www.wtfpl.net/
#
# Please don't use this fucking script, it is shit!
#
ROOT_DIR=$(git rev-parse --show-toplevel)
EXIT=0
# Definitely NSFW
WORD_FILE_URL="http://www.bannedwordlist.com/lists/swearWords.csv"
WORD_FILE_PATH=~/.swearwords.csv
if [ ! -f $WORD_FILE_PATH ]; then
wget -q --header="User-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11" --header="Referer: https://google/" -O - "$WORD_FILE_URL" | tr , '|' > $WORD_FILE_PATH
fi
PATTERN="$(cat $WORD_FILE_PATH)"
for file in $(git diff --cached --name-only --diff-filter=ACM); do
if egrep -Hin "$PATTERN" $file; then
EXIT=1
fi
done
exit $EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment