-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathformat.sh
More file actions
executable file
·41 lines (38 loc) · 837 Bytes
/
format.sh
File metadata and controls
executable file
·41 lines (38 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env bash
if [[ $# -eq 0 ]];
then
paths="src"
else
paths="$@"
fi
# clang-format-13 wraps enum brace even though its option is set to false.
# Use clang-format-14 shipped with npm `clang-format` package
if [[ "$OSTYPE" == "darwin"* ]];
then
arch=$(uname -m)
if [[ "$arch" == "x86_64" ]];
then
formatter=/usr/local/lib/node_modules/clang-format/index.js
elif [[ "$arch" == "arm64" ]];
then
formatter=/opt/homebrew/lib/node_modules/clang-format/index.js
else
echo "ERROR: unsupported architecture( $arch )"
exit 1
fi
else
formatter=clang-format
fi
for path in $paths
do
if [[ -d "$path" ]]
then
find "$path" \( -name "*.h" -o -name "*.cpp" \) -exec $formatter -i --style=file {} \;
else
$formatter -i --style=file "$path"
fi
if [[ $? -ne 0 ]];
then
exit $?
fi
done