-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathupdateExtensionName.sh
More file actions
executable file
·45 lines (36 loc) · 1.18 KB
/
updateExtensionName.sh
File metadata and controls
executable file
·45 lines (36 loc) · 1.18 KB
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
#!/usr/bin/env bash
# Usage: ./rename-plugin.sh oldname:newname [old2:new2 ...]
set -euo pipefail
# Function to rename files, contents, and directories
rename_pair() {
local OLD="$1"
local NEW="$2"
echo "🔁 Replacing '$OLD' with '$NEW'..."
# 1. Rename files with OLD in the name
find . -type f -not -path "*/.git/*" -name "*${OLD}*" | while read -r file; do
dir=$(dirname "$file")
base=$(basename "$file")
new_base="${base//$OLD/$NEW}"
new_path="$dir/$new_base"
mv "$file" "$new_path"
echo "Renamed file: $file -> $new_path"
done
# 2. Replace inside file content
find . -type f -not -path "*/.git/*" -print0 | xargs -0 sed -i "s/${OLD}/${NEW}/g"
# 3. Rename directories (bottom-up)
find . -depth -type d -not -path "*/.git/*" -name "*${OLD}*" | while read -r dir; do
parent=$(dirname "$dir")
base=$(basename "$dir")
new_base="${base//$OLD/$NEW}"
new_path="$parent/$new_base"
mv "$dir" "$new_path"
echo "Renamed directory: $dir -> $new_path"
done
}
# Main loop over all name pairs
for pair in "$@"; do
OLD="${pair%%:*}"
NEW="${pair##*:}"
rename_pair "$OLD" "$NEW"
done
echo "✅ All done, with .git folder safely ignored."