-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrename_project.sh
More file actions
27 lines (22 loc) · 903 Bytes
/
rename_project.sh
File metadata and controls
27 lines (22 loc) · 903 Bytes
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
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 <new_module_name>"
echo "Example: $0 github.com/myuser/myproject"
exit 1
fi
OLD_MODULE="go-layout"
NEW_MODULE="$1"
OS="$(uname)"
echo "Replacing module name from '$OLD_MODULE' to '$NEW_MODULE'..."
# Find all files excluding the scripts themselves and .git directory
# Using LC_ALL=C to handle potential encoding issues
# Using xargs with sed for replacement
if [ "$OS" = "Darwin" ]; then
# macOS requires empty string for -i
grep -rl "$OLD_MODULE" . --exclude-dir=.git --exclude="rename_project.sh" --exclude="rename_project.bat" | xargs sed -i '' "s|$OLD_MODULE|$NEW_MODULE|g"
else
# Linux/GNU sed
grep -rl "$OLD_MODULE" . --exclude-dir=.git --exclude="rename_project.sh" --exclude="rename_project.bat" | xargs sed -i "s|$OLD_MODULE|$NEW_MODULE|g"
fi
echo "Done."
echo "Please run 'go mod tidy' to update dependencies."