32 lines
692 B
Bash
32 lines
692 B
Bash
#!/bin/bash
|
|
|
|
# Variable that will hold the name of the clang-format command
|
|
FMT="clang-format"
|
|
|
|
# Function to format files
|
|
format() {
|
|
for f in $(find "$1" \( -name '*.h' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp' \)); do
|
|
# Skip *_generated.h files
|
|
if [[ "$f" == *_generated.h ]]; then
|
|
continue
|
|
fi
|
|
echo "format ${f}"
|
|
${FMT} -i "${f}"
|
|
done
|
|
echo "~~~ $1 Done ~~~"
|
|
}
|
|
|
|
# Check if argument is provided
|
|
if [ -z "$1" ]; then
|
|
echo "Please provide a directory as an argument."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if directory exists
|
|
if [ ! -d "$1" ]; then
|
|
echo "$1 is not a valid directory."
|
|
exit 1
|
|
fi
|
|
|
|
format "$1"
|