-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_me_check.sh
executable file
·54 lines (47 loc) · 1.21 KB
/
delete_me_check.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
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# List of directories to check
directories=(
"src"
)
# Temporary file to store filenames with the unwanted string
temp_file=$(mktemp)
# This function checks for the unwanted line in a single file
check_file() {
filename="$1"
if grep -q "// ANCHOR - DELETE ME" "$filename"; then
echo "$filename" >>"$temp_file"
fi
}
# Function to check if a file is a text file
is_text_file() {
file_type=$(file -b --mime-type "$1")
if [[ $file_type == text/* ]]; then
return 0 # Text file
else
return 1 # Not a text file
fi
}
# Loop through the directories array and check each directory
for dir in "${directories[@]}"; do
if [ -d "$dir" ]; then
# Find all files in the directory and its subdirectories
find "$dir" -type f -print0 | while IFS= read -r -d '' file; do
if is_text_file "$file"; then
check_file "$file"
fi
done
else
echo "Warning: Directory '$dir' not found."
fi
done
# Display the list of files with the unwanted string
if [ -s "$temp_file" ]; then
echo "Files with '// ANCHOR - DELETE ME' string:"
cat "$temp_file"
exit 1
else
echo "No files with '// ANCHOR - DELETE ME' string found."
exit 0
fi
# Clean up the temporary file
rm "$temp_file"