Created
November 15, 2024 23:52
-
-
Save duduribeiro/d042a94f0ffd9d3233dc6369f92e0f3c to your computer and use it in GitHub Desktop.
Script used to merge a Rails configuration file when running rails app:update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# This script is used to merge a Rails configuration file | |
# with the default configuration file. Helpful when you | |
# run `rails app:update` and you want to merge the changes. | |
# | |
# Usage: MERGE_TOOL=meld THOR_MERGE=~/bin/merge_tool bin/rails app:update | |
RAILS_DEFAULT_CONFIG=$1 | |
APP_CURRENT_CONFIG=$2 | |
# Tip from https://davidrunger.com/blog/using-vs-code-as-a-rails-app-update-merge-tool | |
mkdir -p /tmp/rails-app-update | |
LOCAL=$(mktemp "/tmp/rails-app-update/current") | |
BASE=$(mktemp "/tmp/rails-app-update/base") | |
cp "$APP_CURRENT_CONFIG" "$LOCAL" | |
cp "$APP_CURRENT_CONFIG" "$BASE" | |
# Default to vim if MERGE_TOOL is not set | |
MERGE_TOOL=${MERGE_TOOL:-vim} | |
if [ "$MERGE_TOOL" = "vim" ]; then | |
vimdiff -c "wincmd J" -c "windo set wrap" "$APP_CURRENT_CONFIG" "$LOCAL" "$BASE" "$RAILS_DEFAULT_CONFIG" | |
elif [ "$MERGE_TOOL" = "meld" ]; then | |
meld $LOCAL $APP_CURRENT_CONFIG $RAILS_DEFAULT_CONFIG | |
elif [ "$MERGE_TOOL" = "opendiff" ]; then | |
opendiff $RAILS_DEFAULT_CONFIG $APP_CURRENT_CONFIG | |
elif [ "$MERGE_TOOL" = "code" ]; then | |
code --merge "$RAILS_DEFAULT_CONFIG" "$LOCAL" "$BASE" "$APP_CURRENT_CONFIG" --wait | |
elif [ "$MERGE_TOOL" = "code2way" ]; then | |
code --wait -d $RAILS_DEFAULT_CONFIG $APP_CURRENT_CONFIG | |
elif [ "$MERGE_TOOL" = "rubymine" ]; then | |
rubymine-merge $RAILS_DEFAULT_CONFIG $APP_CURRENT_CONFIG | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment