Skip to content

Instantly share code, notes, and snippets.

@apmiller108
Last active August 6, 2019 03:16
Show Gist options
  • Select an option

  • Save apmiller108/ad5bb208828b2d97f5b09d0c7a90c459 to your computer and use it in GitHub Desktop.

Select an option

Save apmiller108/ad5bb208828b2d97f5b09d0c7a90c459 to your computer and use it in GitHub Desktop.

Revisions

  1. apmiller108 revised this gist Mar 18, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions rename_phoenix_app.sh
    Original file line number Diff line number Diff line change
    @@ -40,9 +40,9 @@ echo -e -n "Please confirm this is correct:\n"\
    read -p "" ANSWER

    if [ "$ANSWER" = "y" ]; then
    grep -l $CURRENT_NAME -r . --exclude-dir=_build --exclude README.md \
    grep -l $CURRENT_NAME -r . --exclude-dir=_build \
    | xargs sed -i '' -e "s/$CURRENT_NAME/$NEW_NAME/g"
    grep -l $CURRENT_OTP -r . --exclude-dir=_build --exclude README.md \
    grep -l $CURRENT_OTP -r . --exclude-dir=_build \
    | xargs sed -i '' -e "s/$CURRENT_OTP/$NEW_OTP/g"

    mv lib/$CURRENT_OTP lib/$NEW_OTP
  2. apmiller108 revised this gist Mar 18, 2017. 1 changed file with 21 additions and 14 deletions.
    35 changes: 21 additions & 14 deletions rename_phoenix_app.sh
    Original file line number Diff line number Diff line change
    @@ -3,32 +3,39 @@
    set -e
    set -o pipefail

    NEW_OTP=$1
    CURRENT_OTP=$1
    NEW_OTP=$2
    CURRENT_NAME=""
    NEW_NAME=""

    # New name argument is required
    if [ $# -eq 0 ]; then
    echo "Please provide a name in snake case. See readme for instructions"\
    "https://github.com/apmiller108/phoenix_starter/blob/master/README.md"
    # New name and current name arguments are required
    if [ $# -ne 2 ]; then
    echo -e "Please provide the current name and new name in snake case\n"\
    "usage: /.rename_phoenix_app.sh current_name new_name"
    exit 64
    fi

    CURRENT_NAME="PhoenixStarter"
    CURRENT_OTP="phoenix_starter"
    # Split snake cased names into array of words.
    IFS="_" read -a current_name_words <<< "$CURRENT_OTP"
    IFS="_" read -a new_name_words <<< "$NEW_OTP"

    # Split snake cased new name into array of words.
    IFS="_" read -a words <<< "$NEW_OTP"
    # Upercase all the words and concatenate them together to derive the CamelCase
    # module names
    for word in "${current_name_words[@]}"; do
    word="$(tr '[:lower:]' '[:upper:]' <<< ${word:0:1})${word:1}"
    CURRENT_NAME="$CURRENT_NAME$word"
    done

    # Upercase all the words and concatenate them together. This derives the app's
    # CamelCase module name.
    for word in "${words[@]}"; do
    for word in "${new_name_words[@]}"; do
    word="$(tr '[:lower:]' '[:upper:]' <<< ${word:0:1})${word:1}"
    NEW_NAME="$NEW_NAME$word"
    done

    # Confirm name change
    echo -e -n "Please confirm this is correct:\nNew name: ${NEW_NAME}\n"\
    "New OTP name: $NEW_OTP\nContinue? [y/n]"
    echo -e -n "Please confirm this is correct:\n"\
    "Change $CURRENT_OTP to $NEW_OTP?\n"\
    "Change $CURRENT_NAME to $NEW_NAME?\n"\
    "Continue? [y/n]"

    read -p "" ANSWER

  3. apmiller108 created this gist Mar 18, 2017.
    47 changes: 47 additions & 0 deletions rename_phoenix_app.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #!/bin/bash

    set -e
    set -o pipefail

    NEW_OTP=$1
    NEW_NAME=""

    # New name argument is required
    if [ $# -eq 0 ]; then
    echo "Please provide a name in snake case. See readme for instructions"\
    "https://github.com/apmiller108/phoenix_starter/blob/master/README.md"
    exit 64
    fi

    CURRENT_NAME="PhoenixStarter"
    CURRENT_OTP="phoenix_starter"

    # Split snake cased new name into array of words.
    IFS="_" read -a words <<< "$NEW_OTP"

    # Upercase all the words and concatenate them together. This derives the app's
    # CamelCase module name.
    for word in "${words[@]}"; do
    word="$(tr '[:lower:]' '[:upper:]' <<< ${word:0:1})${word:1}"
    NEW_NAME="$NEW_NAME$word"
    done

    # Confirm name change
    echo -e -n "Please confirm this is correct:\nNew name: ${NEW_NAME}\n"\
    "New OTP name: $NEW_OTP\nContinue? [y/n]"

    read -p "" ANSWER

    if [ "$ANSWER" = "y" ]; then
    grep -l $CURRENT_NAME -r . --exclude-dir=_build --exclude README.md \
    | xargs sed -i '' -e "s/$CURRENT_NAME/$NEW_NAME/g"
    grep -l $CURRENT_OTP -r . --exclude-dir=_build --exclude README.md \
    | xargs sed -i '' -e "s/$CURRENT_OTP/$NEW_OTP/g"

    mv lib/$CURRENT_OTP lib/$NEW_OTP
    mv lib/$CURRENT_OTP.ex lib/$NEW_OTP.ex
    echo -e "Completed renaming"
    else
    echo -e "exiting"
    exit 0
    fi