Skip to content

Instantly share code, notes, and snippets.

@ph3nx
Created February 8, 2014 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ph3nx/8888806 to your computer and use it in GitHub Desktop.
Save ph3nx/8888806 to your computer and use it in GitHub Desktop.
Shell script to generate an rails app with postgres database in osx mavericks.
#!/bin/bash
case "$1" in
"n" )
if [ -z $2 ]
then
echo "Specify an app name"
else
if [ -d ~/rails/$2 ]
then
echo "App '$2' exists already"
else
rails new "~/rails/$2" -d postgresql
psql --command="create database $2;"
ln -s ~/rails/$2 ~/.pow/
open http://"$2".dev
cd ~/rails/$2
subl ~/rails/$2
fi
fi
;;
"r" )
if [ -z $2 ]
then
echo "Specify an app name"
else
if [ -d /rails/$2 ]
then
echo "Removing app $2"
t=$(date +%Y-%m-%d-%s)
mv ~/rails/$2 ~/rails_bak/$2-$t
rm ~/.pow/$2
echo "Created backup in ~/rails_bak/$2-$t"
else
echo "App '$2' not found"
fi
fi
;;
"o" )
if [ -z $2 ]
then
echo "Specify an app name"
else
if [ -d /rails/$2 ]
then
echo "Opening app.."
open http://$2.dev
cd ~/rails/$2
subl ~/rails/$2
else
echo "App '$2' not found"
fi
fi
;;
*)
echo "There is no command like '$1'"
cat << EOF
Create App:
n app
Remove App
r app
Open App
o app
EOF
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment