Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
set -e
PROJECT_NAME=$1
main() {
display_logo
init_project
choose_branch
search_and_replace_project_name
reset_git
display_finished
}
display_logo() {
cat << "EOS"
_ _ _____ _ _
| \ | | | __ \ (_) | /\
| \| | _____ __ | |__) |__ _ _| |___ / \ _ __ _ __
| . ` |/ _ \ \ /\ / / | _ // _` | | / __| / /\ \ | '_ \| '_ \
| |\ | __/\ V V / | | \ \ (_| | | \__ \ / ____ \| |_) | |_) |
|_| \_|\___| \_/\_/ |_| \_\__,_|_|_|___/ /_/ \_\ .__/| .__/
| | | |
|_| |_|
EOS
}
init_project() {
if [[ -z $PROJECT_NAME ]]; then
printf "\nEnter project name (rails-app): "
read -e PROJECT_NAME
PROJECT_NAME=${PROJECT_NAME:-rails-app}
else
printf "\nProject name: $PROJECT_NAME\n"
fi
echo -e "\nCloning repo..."
git clone git@gitlab.com:jeromedalbert/boilerplate-rails-app.git &> /dev/null
mv boilerplate-rails-app $PROJECT_NAME
cd $PROJECT_NAME
}
choose_branch() {
echo -e "\nChoose a branch:"
echo -e "\033[0;31m master\033[0m"
git branch -r | grep -v master | sed 's/origin\///'
local branch_name
printf 'Enter branch name (master): '
read -e branch_name
branch_name=${branch_name:-master}
git checkout $branch_name &> /dev/null
}
search_and_replace_project_name() {
echo -e "\nSearching and replacing project name..."
local camel_case_name=$(echo $PROJECT_NAME | sed -r 's/(^|-)(\w)/\U\2/g')
local human_name=$(echo $PROJECT_NAME | sed -r -e 's/(^|-)(\w)/ \U\2/g' -e 's/ //')
find . -type f -exec sed -i "s/rails-app/$PROJECT_NAME/g" {} +
find . -type f -exec sed -i "s/RailsApp/$camel_case_name/g" {} +
find . -type f -exec sed -i "s/Rails App/$human_name/g" {} +
}
reset_git() {
echo -e "\nResetting git..."
(
rm -rf .git
git init
git add --all
git commit -m 'Initial commit'
) > /dev/null
}
display_finished() {
echo -e "\nProject \"$PROJECT_NAME\" ready.\n"
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.