Skip to content

Commit c876bab

Browse files
committed
Cleaning up the fmt to use find command
1 parent 7c56128 commit c876bab

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

scripts/fmt.sh

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/bin/bash
2+
# Used to format files to the given format using clang format.
23

34
# Variable that will hold the name of the clang-format command
45
FMT=""
56

6-
FOLDERS=("src" "test")
7-
87
# Some distros just call it clang-format. Others (e.g. Ubuntu) are insistent
98
# that the version number be part of the command. We prefer clang-format if
10-
# that's present, otherwise we check clang-format-13
9+
# that's present, otherwise we check clang-format-13
1110
for clangfmt in clang-format{,-13}; do
1211
if which "$clangfmt" &>/dev/null; then
1312
FMT="$clangfmt"
@@ -21,21 +20,6 @@ if [ -z "$FMT" ]; then
2120
exit 1
2221
fi
2322

24-
function format() {
25-
# ignore getRSS.h file
26-
for f in $(find $@ -name '*.h' ! -iname 'getRSS.h' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp'); do
27-
echo "format ${f}";
28-
${FMT} -i ${f};
29-
done
30-
31-
echo "~~~ $@ Done ~~~";
32-
}
23+
files=$(find . \( -path ./build -prune -o -path ./.git -prune \) -o -type f -name "*[h|c]pp" -print)
3324

34-
# Check all of the arguments first to make sure they're all directories
35-
for dir in ${FOLDERS[@]}; do
36-
if [ ! -d "${dir}" ]; then
37-
echo "${dir} is not a directory";
38-
else
39-
format ${dir};
40-
fi
41-
done
25+
${FMT} -i ${files}

0 commit comments

Comments
 (0)