Skip to content

Instantly share code, notes, and snippets.

@justdan96
Created October 24, 2022 18:48
Show Gist options
  • Save justdan96/c5ec33a3cfdd84e9b7d6a19abcdbc8ee to your computer and use it in GitHub Desktop.
Save justdan96/c5ec33a3cfdd84e9b7d6a19abcdbc8ee to your computer and use it in GitHub Desktop.
#!/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