-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclang-format-all
52 lines (46 loc) · 913 Bytes
/
clang-format-all
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
42
43
44
45
46
47
48
49
50
51
52
# Based on @asimilon's: https://github.com/asimilon/clangformat
#!/bin/bash
function usage() {
cat << END
Usage: clangformat <directory> [--test]
Use --test to show which files would be formatted.
END
}
if [[ ! -n "$1" ]]; then
echo "Provide a directory to clangformat!"
usage
exit 1
fi
if [[ $1 == "--help" ]]; then
usage
exit 0
fi
CLANGFMT="clang-format"
if [[ -f ".clang-format-ignore" ]]; then
EXCLUDES=`cat .clang-format-ignore`
echo Excluding : $EXCLUDES
else
EXCLUDES=""
fi
for F in `find "$1"`; do
DOFMT=TRUE
if [[ -n $EXCLUDES ]]; then
while read -r EXCL; do
if [[ -n $EXCL && $EXCL != /#* ]]; then
if [[ $F == $EXCL ]]; then
DOFMT=FALSE
break
fi
fi
done <<< "$EXCLUDES"
fi
if [[ $DOFMT == TRUE ]]; then
if [[ -f $F ]]; then
if [[ $2 == "--test" ]]; then
echo "Would format $F"
else
$CLANGFMT -i -verbose -style=file "$F"
fi
fi
fi
done