-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprepare.sh
executable file
·63 lines (57 loc) · 1.42 KB
/
prepare.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
55
56
57
58
59
60
61
62
63
#!/bin/bash
# Variables
EXCLUDING_FOLDERS=("node_modules" "dist" "venv" ".git" "$git" "$" "out" "bin")
EXCLUDING_VALUES=("FALCION" "PATTERNU" "PATTERNUGIT" "PATTERNUGIT.NET")
ROOT_DIRECTORY=$(pwd)
# Logging functions
info() {
echo "[INFO] $1"
}
# Search function
search() {
local filepath="$1"
info "Searching in $filepath"
while IFS= read -r line; do
for word in "${EXCLUDING_VALUES[@]}"; do
if [[ "$line" == *"$word"* ]]; then
info "Found \"$word\" in $filepath"
fi
done
done <"$filepath"
}
# Traverse function
traverse() {
local directory="$1"
info "Traversing directory: $directory"
for item in "$directory"/*; do
if [ -d "$item" ]; then
local dirname
dirname=$(basename "$item") # Declare and assign separately
# Use a loop to check against the EXCLUDING_FOLDERS array
local exclude=false
for excluded in "${EXCLUDING_FOLDERS[@]}"; do
if [[ "$dirname" == "$excluded" ]]; then
exclude=true
break
fi
done
if [ "$exclude" = false ]; then
traverse "$item"
fi
elif [ -f "$item" ]; then
info "Processing file: $item"
search "$item"
fi
done
}
# Main script
echo "Do you want to update the settings? (Y/N/IGNORE)"
read -r mode
if [[ "$mode" != "IGNORE" ]]; then
echo "Enter words separated by a comma:"
read -r params
IFS=',' read -ra entries <<<"$params"
info "Updating settings with: ${entries[*]}"
EXCLUDING_VALUES+=("${entries[@]}")
fi
traverse "$ROOT_DIRECTORY"