Skip to content

Instantly share code, notes, and snippets.

@andyg1
Created December 16, 2016 10:56
Show Gist options
  • Save andyg1/9d43c9f7e615ba59e669068e6e4db627 to your computer and use it in GitHub Desktop.
Save andyg1/9d43c9f7e615ba59e669068e6e4db627 to your computer and use it in GitHub Desktop.
#!/bin/bash
# checks any .php files that are edited in the current branch for syntax errors
# reports a list of files, putting errors in red and reporting the error and line number
FILES=$(git status -s | grep '\.php$')
for f in $FILES
do
if [[ $f =~ ^.*\.php$ ]]; then
RESULT=$(php -l $f 2>&1)
if [[ ! $RESULT == *"No syntax errors detected"* ]] || [[ $RESULT == *"on line"* ]]; then
RESULT="\033[31m$RESULT\e[0m"
fi
echo -e "$RESULT"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment