-
Notifications
You must be signed in to change notification settings - Fork 0
/
clang-format.sh
executable file
·39 lines (38 loc) · 1.04 KB
/
clang-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
#!/bin/bash
parse_args() {
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-f)
echo "Clang formatting the files specified"
clang-format -style=file -i -fallback-style=none $2
shift # past argument
shift # past value
;;
-d)
echo "Clang formatting all files in the directory"
find $2 -iname *.h -o -iname *.c -o -iname *.h | xargs clang-format -style=file -i -fallback-style=none
shift # past argument
shift # past value
;;
-g)
echo "Clang formatting only git diff'ed output"
clang-format -style=file -fallback-style=none -i `git ls-files -om "*.[ch]"`
shift # past argument
;;
-h|--help)
echo "-f: Pass list of files to be clang formatted"
echo "-a: Clang format all files in the project"
echo "-d: Clang format all files in the directory passed after this option"
echo "-g: Clang formatting only git diff'ed output"
exit 0
;;
*) # unknown option
echo "Unknown option $key"
exit 1
;;
esac
done
}
parse_args $@