-
Notifications
You must be signed in to change notification settings - Fork 14
/
format.sh
41 lines (34 loc) · 863 Bytes
/
format.sh
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
#!/bin/bash
FIND=${FIND:=find}
if [[ "$OSTYPE" == "darwin"* ]]; then
FIND_ARG0=-E
else
FIND_ARG1="-regextype posix-extended"
fi
PIDCounter=0
function FormatFolderRecursiveAsync() {
if [[ ! -d "$1" ]]; then
echo "Folder not found: $1"
return
fi
while read file; do
if [[ $file == shards/gfx/rust/wgpu-native* ]]; then
echo "Ignoring $file"
continue
fi
echo "Formatting $file"
clang-format -i $file &
local PID=$!
PIDs[${PIDCounter}]=$PID
PIDCounter=$(($PIDCounter+1))
done <<<"$($FIND $FIND_ARG0 "$1" $FIND_ARG1 -regex '.*\.(cpp|hpp|h)')"
}
function AsyncWait() {
for pid in ${PIDs[*]}; do
wait $pid
done
}
FormatFolderRecursiveAsync include
FormatFolderRecursiveAsync shards
AsyncWait
echo "Formatted ${#PIDs[@]} files"