Last active
April 15, 2017 04:48
-
-
Save rusilko/5995661 to your computer and use it in GitHub Desktop.
Simple bash script to quickly fire up your Rails working environment.
This file contains hidden or 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
#!/bin/bash | |
# Function displaying wrong usage information | |
# Proper usage is: ./dev_start.sh Rails-Project-Folder | |
usage() | |
{ | |
cat << EOF | |
usage: $0 Rails-Project-Folder | |
EOF | |
} | |
# Display usage info when no arg is passed | |
PROJECT=$1 | |
if [[ -z $PROJECT ]] | |
then | |
usage | |
exit 1 | |
fi | |
# Seting some variables | |
BASH_LOGIN="/bin/bash -l -c" | |
RVM_RELOAD="rvm reload" | |
SERVER_URL="localhost:3000" | |
SUBLIME_PATH="/usr/bin/subl" | |
# Warning: code below will work only if you've cloned repo using ssh link | |
GITHUB_URL=`cat $PWD/$1/.git/config | \ | |
awk '/\[remote "origin"\]/{seen = 1} seen {print}' | \ | |
grep -m 1 url | \ | |
sed -e 's/:/\//' -e 's/url = git@//' -e 's/\.git//'` | |
APP_URLS="$SERVER_URL $GITHUB_URL" | |
# Set vars for terminal windows | |
# TERMINAL 1 - rails server | |
SERVER_TITLE="[SERVER]" | |
SERVER_PROFILE="Rails-server" | |
SERVER_COMMAND="bundle exec rails s" | |
# TERMINAL 2 - guard for testing | |
GUARD_TITLE="[GUARD]" | |
GUARD_PROFILE="Rails-guard" | |
GUARD_COMMAND="bundle exec guard" | |
# TERMINAL 3 - rails console | |
CONSOLE_TITLE="[CONSOLE]" | |
CONSOLE_PROFILE="Rails-console" | |
CONSOLE_COMMAND="bundle exec rails c" | |
# Kick your console with 3 tabs | |
gnome-terminal --working-directory="$PWD/$PROJECT" \ | |
--tab-with-profile=$SERVER_PROFILE --title=$SERVER_TITLE \ | |
-e "$BASH_LOGIN \"$RVM_RELOAD && $SERVER_COMMAND\"" \ | |
\ | |
--tab-with-profile=$GUARD_PROFILE --title=$GUARD_TITLE \ | |
-e "$BASH_LOGIN \"$RVM_RELOAD && $GUARD_COMMAND\"" \ | |
\ | |
--tab-with-profile=$CONSOLE_PROFILE --title=$CONSOLE_TITLE \ | |
-e "$BASH_LOGIN \"$RVM_RELOAD && $CONSOLE_COMMAND\"" | |
# Kick text editor of your choice (sublime) | |
/usr/bin/nohup nice $SUBLIME_PATH -a $PWD/$PROJECT/. >/dev/null 2>&1 & | |
# Kick a browser with app and other tabs (like github for example) | |
sleep 10 # wait for rails s to start | |
chromium-browser --new-window --fast-start $APP_URLS 1>/dev/null & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment