-
Notifications
You must be signed in to change notification settings - Fork 0
/
replace.sh
32 lines (29 loc) · 1.11 KB
/
replace.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
# Rename all "ai-development" from blueprint to TARGET_STRING_HYPHEN (Github and folders prefer hyphens).
# Rename all "ai_development" from blueprint to TARGET_STRING_UNDERSCORE (Python prefers underscores).
# Global variables
TARGET_STRING_HYPHEN="my-project"
TARGET_STRING_UNDERSCORE="my_project"
# Function to recursively rename files and directories
rename_recursive() {
shopt -s dotglob # Include hidden files
for file in "$1"/*; do
new_file="${file//ai-development/$TARGET_STRING_HYPHEN}"
new_file="${new_file//ai_development/$TARGET_STRING_UNDERSCORE}"
if [ "$file" != "$new_file" ]; then
mv "$file" "$new_file"
file="$new_file"
fi
if [ -d "$file" ]; then
rename_recursive "$file"
else
mime_type=$(file --mime-type -b "$file")
if [[ $mime_type == text/* || "${file##*.}" == "json" ]]; then
sed -i "s/ai-development/$TARGET_STRING_HYPHEN/g" "$file"
sed -i "s/ai_development/$TARGET_STRING_UNDERSCORE/g" "$file"
fi
fi
done
shopt -u dotglob # Revert to default (exclude hidden files)
}
# Call function with root directory
rename_recursive .