#!/bin/sh function read_title() { printf "Enter app display name: " >&2 read TITLE < /dev/tty if [ -z "${TITLE}" ]; then echo "Name is required." >&2 return 1 fi echo $TITLE return 0 } function app_slug() { echo "$@" \ | sed -E 's/([a-z0-9])([A-Z])/\1-\2/g' \ | tr ' _' '-' \ | tr '[:upper:]' '[:lower:]' \ | sed -E 's/[^a-z0-9-]//g' \ | sed -E 's/-{2,}/-/g' } function ensure_app_name_and_slug() { if [ -z "${APP_NAME}" ]; then if ! APP_NAME=$(read_title); then exit 1 fi export APP_NAME fi if [ -z "${APP_SLUG}" ]; then export APP_SLUG=$(app_slug "$APP_NAME") fi } if [[ -n "${BASH_VERSION:-}" ]]; then SCRIPT_PATH="${BASH_SOURCE[0]}" else SCRIPT_PATH="${(%):-%N}" fi # Prevent execution if being sourced if [[ ! -f "$SCRIPT_PATH" ]]; then ensure_app_name_and_slug echo "app name: $APP_NAME" echo "app slug: $APP_SLUG" git clone --depth 1 --recurse-submodules --shallow-submodules ssh://git@bitbucket.org/musopia/new-app "${APP_SLUG}" cd "${APP_SLUG}" echo "" source Template/setup.sh fi