danielhoherd/pre-commit-hooks

New hook: remove unicode quotes

Opened this issue · 0 comments

Add a hook to replace unicode quotes with normal quotes. EG:

$ cat ~/code/dho-bin/fix-shitty-quotes.sh
#!/usr/bin/env bash
# shellcheck disable=SC1111
# Purpose: Remove unicode quotes from content.
# Caveats: This is just a dump search/replace. It does not account for quoted
#          content that will be misquoted after removing unicode quotes.

if [ "${#@}" -lt 1 ]; then
    echo "Replaces shitty quotes with normal quotes in all given files"
    echo "example: grep -rl '[“”’]' | xargs ${0##*/}"
    exit 1
fi

if [ "$(uname)" == 'Darwin' ]; then
    [ ! -e /usr/local/bin/gsed ] && {
        echo "GNU sed is required because bsd sed is lame."
        exit 1
    }
    /usr/local/bin/gsed -i 's/[“”]/"/g' "$@"
    /usr/local/bin/gsed -i "s/’/'/g" "$@"
else
    sed -i 's/[“”]/"/g' "$@"
    sed -i "s/’/'/g" "$@"
fi