-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathformat.sh
38 lines (31 loc) · 898 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
#!/usr/bin/env bash
set -e
usage()
{
echo "Usage: $0 [-h] [-a/--all]"
echo
echo "arguments:"
echo " -a, --all format all files in the repo"
echo " -h, --help show this help message and exit"
exit 2
}
if ! type astyle &> /dev/null
then
echo "Error: astyle is not installed or is not on the PATH."
echo "Please install astyle to use this tool."
exit 1
fi
WORKSPACE_DIR=$(git rev-parse --show-toplevel)
cd "$WORKSPACE_DIR"
if [ "$#" -eq 0 ] ; then
ALL_FILES=$({ git ls-files -o --exclude-standard && git diff --diff-filter=d --name-only master; })
elif [ "$1" = "-a" ] || [ "$1" = "--all" ] ; then
ALL_FILES=$({ git ls-files -cmo --exclude-standard; })
else
usage
fi
FILES=$(echo "$ALL_FILES" | grep -v 'mcc_generated_files' | grep -E '\.c$|\.h$|\.cpp$|\.hpp$|\.cc$|\.hh$|\.ino$')
if [ ! -z "$FILES" ]
then
astyle --project=.astylerc -n $FILES
fi