Skip to content

Commit

Permalink
Added rename script and readme usage
Browse files Browse the repository at this point in the history
  • Loading branch information
igolaizola committed Feb 18, 2023
1 parent e517683 commit ade0126
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
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
```
35 changes: 35 additions & 0 deletions rename.sh
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

0 comments on commit ade0126

Please sign in to comment.