Skip to content

Instantly share code, notes, and snippets.

@skwashd
Last active February 28, 2024 11:11
Show Gist options
  • Save skwashd/8732878 to your computer and use it in GitHub Desktop.
Save skwashd/8732878 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!
#
# If you want to commit something with swearing use FUCK_IT=1 git commit ...
if [ ! -z "$FUCK_IT" ]; then
exit 0
fi
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
@Nnoerregaard
Copy link

@62mkv
Copy link

62mkv commented Feb 21, 2022

@pmoranga
Copy link

I added multi-language support and example to use with https://pre-commit.com/ here https://gist.github.com/pmoranga/c6997d08fa1e7b51625bf532ca1c603e

@trallnag
Copy link

Helpful to make sure that debug print statements don't end up in commits.

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