Skip to content

Instantly share code, notes, and snippets.

@pmoranga
Forked from skwashd/pre-commit
Last active February 28, 2024 11:14

Revisions

  1. pmoranga revised this gist May 24, 2022. 3 changed files with 61 additions and 33 deletions.
    15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    ## Example using https://pre-commit.com/
    repos:
    - repo: local
    hooks:
    - id: dontship
    name: DONTSHIP check - Block words
    entry: '\bdie\b'
    language: pygrep # https://pre-commit.com/#pygrep
    types: [php]

    - id: check-swear
    name: Check Swear Words
    entry: ./scripts/check_swear_words.sh
    language: script

    46 changes: 46 additions & 0 deletions check_swear_words.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #!/bin/bash

    ## This script should run under pre-commit control and return error in case of any bad word is present in the files staged

    # If you want to commit something with swearing use FUCK_IT=1 git commit ...
    if [ -n "$FUCK_IT" ]; then
    exit 0
    fi

    ROOT_DIR=$(git rev-parse --show-toplevel)
    EXIT=0


    # Definitely NSFW
    WORD_FILE_URL_BASE="https://raw.githubusercontent.com/LDNOOBW/List-of-Dirty-Naughty-Obscene-and-Otherwise-Bad-Words/master/"
    WORD_FILE_PATH_BASE=~/.swearwords

    TMPFILE=$(mktemp)

    check_for_words(){
    LANG=$1

    if [ ! -f "${WORD_FILE_PATH_BASE}-${LANG}" ]; then
    wget -q -O - "${WORD_FILE_URL_BASE}/${LANG}" | tr '\n' '|' | sed 's/\|$//g' > "${WORD_FILE_PATH_BASE}-${LANG}"
    fi

    PATTERN="$(cat ${WORD_FILE_PATH_BASE}-${LANG} )"
    if [[ -n "$PATTERN" ]]; then
    for file in $(git diff --cached --name-only --diff-filter=ACM); do
    if egrep -Hinw "$PATTERN" "$file" > $TMPFILE ; then
    echo "Swear word with language: ${LANG} found in file: $(cat $TMPFILE)"
    rm $TMPFILE
    return 1
    fi
    done
    fi
    return 0
    }

    for i in en fr pt ru it es; do
    check_for_words $i || exit 1
    done

    rm $TMPFILE

    exit 0
    33 changes: 0 additions & 33 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -1,33 +0,0 @@
    #!/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
  2. @skwashd skwashd revised this gist Jan 31, 2014. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,11 @@
    # 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

  3. @skwashd skwashd revised this gist Jan 31, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pre-commit
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ fi

    PATTERN="$(cat $WORD_FILE_PATH)"
    for file in $(git diff --cached --name-only --diff-filter=ACM); do
    if egrep -Hinw "$PATTERN" $file; then
    if egrep -Hin "$PATTERN" $file; then
    EXIT=1
    fi
    done
  4. @skwashd skwashd created this gist Jan 31, 2014.
    28 changes: 28 additions & 0 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/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 -Hinw "$PATTERN" $file; then
    EXIT=1
    fi
    done

    exit $EXIT