-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrename.sh
executable file
·38 lines (29 loc) · 879 Bytes
/
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
#!/bin/bash
# Treat unset variables as an error
set -u
# Exit on error
set -e
# Obtain repository owner and name from argument
owner=$(echo "$1" | cut -d'/' -f1)
name=$(echo "$1" | cut -d'/' -f2)
# Check if owner or name are empty
if [ -z "$owner" ] || [ -z "$name" ]; then
echo "Invalid repository name '$1'"
exit 1
fi
# Lowercase and uppercase
name_low=$(echo "$name" | tr '[:upper:]' '[:lower:]')
name_upp=$(echo "$name" | tr '[:lower:]' '[:upper:]')
# Rename files and folders
mv cmd/goobar "cmd/$name_low"
mv goobar.go "$name_low.go"
# Replace file contents
find . -type f -exec sed -i "s/goobar/$name_low/g" {} \;
find . -type f -exec sed -i "s/GOOBAR/$name_upp/g" {} \;
find . -type f -exec sed -i "s/igolaizola/$owner/g" {} \;
# Override README.md
echo "# $name" > README.md
# Remove this script folder
rm -rf rename.sh
# Remove .git folder
rm -rf .git