Created
February 13, 2020 17:00
-
-
Save hovissimo/de0b03df0758ca39427641fd9b870f44 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/zsh | |
# Redirect output to stderr. | |
exec 1>&2 | |
# join_by from https://stackoverflow.com/questions/1527049/how-can-i-join-elements-of-an-array-in-bash | |
function join_by { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; } | |
# pattern is just all of these strings smushed into a big regex pattern | |
booboos=( | |
# ruby debug tools | |
'byebug' | |
'binding.pry' | |
'pry-rescue/minitest' | |
# frontend debug tools | |
'debugger' | |
'console\.' # console.log, console.warn, console.error | |
# frontend test limiters | |
'.only(' | |
'.skip(' | |
# special comments | |
'DO NOT COMMIT' | |
'TODO' | |
# merge tokens | |
'[<>|=]\{7\}' | |
) | |
pattern=$(join_by '\|' ${booboos[@]}) | |
if test $(git diff --cached | grep ^+\[^+] | grep -e $pattern | wc -l) != 0 | |
then | |
for file in $(git diff --cached --name-only); do | |
# This next line shows the offending tokens, but it shows them from the working directory and not from the staging area. | |
# TODO: Make this show problems in the staging area instead, because that's what you're trying to commit. | |
# (If the problem is fixed in the working directory but not in the staged files, this tool will puke but not show you the error) | |
grep --color -Hne $pattern $file # output matches | |
done | |
echo "\nFound a boo-boo in your cached files." | |
echo "Enter \"I'm naughty\" to continue, anything else to exit." | |
vared -ce response | |
if [[ ! $response == "I'm naughty" ]] | |
then | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment