From ade012634080f743de3e4a991b4aa1a45cc29047 Mon Sep 17 00:00:00 2001 From: igolaizola <11333576+igolaizola@users.noreply.github.com> Date: Sun, 19 Feb 2023 00:02:25 +0100 Subject: [PATCH] Added rename script and readme usage --- README.md | 9 +++++++++ rename.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 rename.sh diff --git a/README.md b/README.md index 524b9f0..de874df 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/rename.sh b/rename.sh new file mode 100755 index 0000000..7a3214d --- /dev/null +++ b/rename.sh @@ -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