forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
format
executable file
·42 lines (36 loc) · 1.08 KB
/
format
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
#!/bin/bash
#
# Script uses clang-format to format all of the source files in a
# default format.
#
# The absolute path of the directory containing this script.
DIR="$( cd "$( dirname "$0" )" && pwd)"
# Define top level project directory
PROJECT_DIR="${DIR}"
METHOD="GIT"
if [ -n "$1" ]; then
METHOD=$1
fi
# Paths to format
MONITOR=()
MONITOR+=( "${PROJECT_DIR}/Source" )
if [ "$METHOD" == "ALL" ]; then
# Format all Source files
for FILE in $(find ${MONITOR[*]} -type f \( -iname "*.mm" -o -iname "*.m" -o -iname "*.h" \))
do
clang-format -style=file -i "$FILE" &
done
elif [ "$METHOD" == "GIT" ]; then
# Gather all added or modified files from git and format them
CHANGED_FILES=$(git ls-files --other --modified --exclude-standard | grep ".*[\.m|\.mm|\.h|\.hpp]$")
for CHANGED_FILE in $CHANGED_FILES
do
clang-format -style=file -i "${PROJECT_DIR}/$CHANGED_FILE" &
done
else
echo "Usage: $0 [GIT|ALL]";
echo "GIT: Only format added or modified files"
echo "ALL: Format all files"
fi
# Wait until all clang-format invoctations are done
wait