Skip to content

Instantly share code, notes, and snippets.

@ywkaras
Last active February 11, 2020 22:40
Show Gist options
  • Save ywkaras/8e6dc1994ac0dfa9155a0cd02cb37e52 to your computer and use it in GitHub Desktop.
Save ywkaras/8e6dc1994ac0dfa9155a0cd02cb37e52 to your computer and use it in GitHub Desktop.
Bash script for efficiently running clang-format on Linux
if [[ "$(uname)" != Linux ]] ; then
echo "This script only runs on Linux"
exit 1
fi
if [[ ! -d .git ]] ; then
echo "Not at root of repo"
exit 1
fi
DID_IT=N
if [[ ! -f .srcfmt ]] ; then
make -j clang-format
if [[ "$?" != 0 ]] ; then
echo "FAILURE running clang-format"
exit 1
fi
find . -type f | while read F
do
file $F | grep -F "with CRLF line terminators"
done
else
FMT="$( find . -name clang-format.linux | tail -n 1 )"
if [[ "$FMT" = "" ]] ; then
echo "can't find clang-format.linux"
fi
find . -iname \*.[ch] -o -iname \*.cc -o -iname \*.h.in | while read F
do
if [[ "$F" -nt .srcfmt ]] ; then
echo $F
$FMT -i $F
if [[ "$?" != 0 ]] ; then
echo "FAILURE running clang-format"
exit 1
fi
fi
done
find . -type f | while read F
do
if [[ "$F" -nt .srcfmt ]] ; then
file $F | grep -F "with CRLF line terminators"
fi
done
fi
date >| .srcfmt
echo "ran clang-format" >> .srcfmt
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment