Created
October 24, 2022 18:48
-
-
Save justdan96/c5ec33a3cfdd84e9b7d6a19abcdbc8ee to your computer and use it in GitHub Desktop.
This file contains 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/bash | |
set -e | |
function append_newline { | |
if [[ -z "$(tail -c 1 "$1")" ]]; then | |
: | |
else | |
echo >> "$1" | |
fi | |
} | |
if [ -z "$1" ]; then | |
TARGET_DIR="." | |
else | |
TARGET_DIR=$1 | |
fi | |
pushd ${TARGET_DIR} >> /dev/null | |
# Find all source files using Git to automatically respect .gitignore | |
FILES=$(git ls-files "*.h" "*.cpp" "*.c") | |
# Run clang-format | |
clang-format -i ${FILES} | |
# Check newlines | |
for f in ${FILES}; do | |
append_newline $f | |
done | |
popd >> /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment