-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added rename script and readme usage
- Loading branch information
1 parent
e517683
commit ade0126
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
# goobar | ||
|
||
Skeleton for golang projects | ||
|
||
## Usage | ||
|
||
```bash | ||
git clone https://github.com/igolaizola/goobar project | ||
cd project | ||
./rename.sh owner/project | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/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" {} \; | ||
|
||
# Remove this script folder | ||
rm -rf rename.sh | ||
|
||
# Remove .git folder | ||
rm -rf .git |