-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathformat_sources.sh
executable file
·41 lines (33 loc) · 991 Bytes
/
format_sources.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
40
41
#!/bin/bash
# Define directories to skip
SKIP_DIRS=("build" "cmake")
# Function to check if directory should be skipped
should_skip() {
for dir in "${SKIP_DIRS[@]}"; do
if [[ "$1" == *"/$dir/"* ]]; then
return 0 # 0 means true in bash, so skip
fi
done
return 1 # 1 means false in bash, so don't skip
}
# Main loop to find and format files
find . -type f \( -iname \*.h -o -iname \*.hpp -o -iname \*.cc -o -iname \*.c -o -iname \*.cpp \) | while read -r file; do
if should_skip "$file"; then
# echo "Skipping $file"
continue
fi
# Create a temporary file to store the original content
temp_file=$(mktemp)
cp "$file" "$temp_file"
# Format the file
clang-format -i "$file"
# Check if the file was changed by comparing it to the temporary file
if ! cmp -s "$file" "$temp_file"; then
echo "Formatted $file"
# else
# echo "$file unchanged."
fi
# Clean up the temporary file
rm "$temp_file"
done
echo "Formatting complete."