-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.sh
More file actions
executable file
·31 lines (26 loc) · 939 Bytes
/
format.sh
File metadata and controls
executable file
·31 lines (26 loc) · 939 Bytes
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
#!/bin/bash
# Name: format.sh
# Micras Team
# Brief: Format the code using clang-format
# 04/2023
Green='\033[0;32m' # Green
BGreen='\033[1;32m' # Bold Green
BPurple='\033[1;35m' # Bold Purple
# Check if clang-format is installed
if ! [ -x "$(command -v clang-format)" ]; then
echo 'Error: clang-format is not installed.' >&2
exit 1
fi
# Find all C, C++ and header files excluding specified directories
FILES=$(find . \( -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" \) \
-not \( -path "*/build/*" -o -path "./MicrasFirmware/*" \))
# Loop through each file and format if found
for FILE in $FILES; do
# Check if the file exists and is readable
if [ -f "$FILE" ] && [ -r "$FILE" ]; then
# Format the file using clang-format
clang-format -style=file -i "$FILE"
echo -e "${BGreen}Formatted: ${Green}$FILE"
fi
done
echo -e "${BPurple}Formatting complete."