Skip to content

Instantly share code, notes, and snippets.

@silverweed
Created September 25, 2017 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silverweed/768e50c681604862bfdba0d0ca059390 to your computer and use it in GitHub Desktop.
Save silverweed/768e50c681604862bfdba0d0ca059390 to your computer and use it in GitHub Desktop.
Git hook that warns when there are lines longer than 120 characters
#!/bin/bash
HARDLIMIT=120
FOUND=$(find src/ -not -path \*third\* -type f -name \*pp -exec awk -v HL=$HARDLIMIT '
length($0) > HL {
printf "%s:%d %s", FILENAME, FNR, $0
}' {} +)
if [[ -n $FOUND ]]; then
echo "Following lines are longer than hardlimit $HARDLIMIT:"
while read LINE; do echo $LINE; done < <(echo -e $FOUND)
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment