-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathformat
More file actions
executable file
·77 lines (65 loc) · 1.24 KB
/
format
File metadata and controls
executable file
·77 lines (65 loc) · 1.24 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
set -eu
e () {
echo "$@"
eval "$@"
}
if [ "${1:-x}" = "-h" ] || [ "${1:-x}" = "--help" ] ; then
echo >&2 "usage: $0 [--help] [-y] [FILE=\`ap.findsource\`] ...
Run clang-format for C/C++ files found recursively from current directory or specified in arguments.
Options:
-y
Proceed without confirmation.
"
exit 1
fi
force=0
if [ "${1:-x}" = "-y" ] ; then
force=1
shift
fi
list=/tmp/clang-format-list.$$
tmp=/tmp/tmp.$$
trap 'rm -f $list $tmp; exit 2' 1 2 3 4 15
if [ "$#" -gt "0" ] ; then
rm -f "$list"
for arg in "$@" ; do
echo "$arg" >> "$list"
done
else
ap.findsource > "$list"
fi
# exclude symlinks, 'clang-format -i' replaces symlinks with regular files
echo "Excluded symlinks:"
rm -f "$tmp"
while read line ; do
if [ -L "$line" ] ; then
echo "$line"
else
echo "$line" >> "$tmp"
fi
done < "$list"
mv "$tmp" "$list"
echo "Remaining files:"
cat $list
cmd="clang-format -i"
echo >&2 "Running '$cmd' for these files."
re=
if [ "$force" == "1" ] ; then
re='y'
else
read -r -p "Proceed? [y/N] " re
fi
if [ "$re" = "y" ] ; then
cat "$list" | xargs $cmd
rm -v "$list"
echo >&2 Done
exit 0
else
rm -v "$list"
echo >&2 Abort
exit -1
fi
status=$?
rm -f $list
exit $status