-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrename.sh
executable file
·51 lines (37 loc) · 1.32 KB
/
rename.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
#!/bin/bash
# Usage: ./rename.sh NEW_NAME
if [ "$#" -ne 1 ]; then
echo "❌ usage: $0 new_name"
exit 1
fi
OLD_NAME="BoilerplateApp"
NEW_NAME="${1%/}" # Remove any trailing slashes
echo "🔍 old name: ${OLD_NAME}"
echo "🔍 new name: ${NEW_NAME}"
process_file() {
local file="$1"
if file --mime "$file" | grep -q 'charset=binary'; then
echo "⚙️ skipping binary file: $file"
else
echo "🔄 processing file: $file"
sed -i '' "s/${OLD_NAME}/${NEW_NAME}/g" "$file"
fi
}
export -f process_file
export OLD_NAME
export NEW_NAME
echo "🔄 replacing old project name with new project name in all files..."
find . -type f -not -path '*/\.git/*' -exec bash -c 'process_file "$1"' _ {} \;
echo "🔄 staging changes..."
git add -A
echo "🔄 renaming directories..."
find . -depth -name "*${OLD_NAME}*" -not -path '*/\.git/*' -execdir bash -c 'git mv "$1" "${1//'"${OLD_NAME}"'/'"${NEW_NAME}"'}"' _ {} \;
echo "🔄 renaming files..."
find . -name "*${OLD_NAME}*" -not -path '*/\.git/*' -exec bash -c 'git mv "$1" "${1//'"${OLD_NAME}"'/'"${NEW_NAME}"'}"' _ {} \;
echo "🧹 cleaning up backup files..."
find . -type f -name "*''" -delete
echo "🔄 staging renamed files..."
git add -A
echo "📝 committing changes..."
git commit -m "chore: rename project from ${OLD_NAME} to ${NEW_NAME}"
echo "✅ renaming complete."