Skip to content

Instantly share code, notes, and snippets.

@takumikinjo
Created June 3, 2012 09:46
Show Gist options
  • Save takumikinjo/2862788 to your computer and use it in GitHub Desktop.
Save takumikinjo/2862788 to your computer and use it in GitHub Desktop.
startup script for my rails app dev
#!/usr/bin/env bash
# tested on ubuntu12.04 server
# this cannot perform on lion. lion's ed command does not have 'y' command.
# rails new my-app
# cd my-app
# bash < <(curl -s https://raw.github.com/gist/2862788/ed729517cc94c3c3aee44bdbec1f3039184d5181/startup.sh)
git init
git add .
git commit -m 'init'
if ! `grep -q TAGS .gitignore && grep -q tags .gitignore`; then
cat <<EOF | ed .gitignore
\$a
TAGS
tags
.
w
EOF
git add .
git commit -m 'edit .gitignore to ignore TAGS and tags'
fi
if grep -q "# gem 'therubyracer'" Gemfile; then
cat <<EOF | ed Gemfile
/# gem 'therubyracer'/
.c
gem 'therubyracer', :platforms => :ruby
.
w
EOF
bundle install
git add .
git commit -m "comment in gem 'therubyracer'"
fi
if grep -q "# gem 'debugger'" Gemfile; then
cat <<EOF | ed Gemfile
/# gem 'debugger'/
.c
gem 'debugger'
.
w
EOF
bundle install
git add .
git commit -m "comment in gem 'debugger'"
fi
if ! `grep -q pry-doc Gemfile && grep -q pry-rails Gemfile`; then
if grep -q 'group :development, :test do' Gemfile; then
cat <<EOF | ed Gemfile
/group :development, :test do/
.c
group :development, :test do
gem 'pry-rails'
gem 'pry-doc'
.
w
EOF
else
cat <<EOF | ed Gemfile
\$a
group :development, :test do
gem 'pry-rails'
gem 'pry-doc'
end
.
w
EOF
fi
bundle install
git add .
git commit -m "install pry-rails and pry-doc"
fi
if ! grep -q haml-rails Gemfile; then
if grep -q 'group :development, :test do' Gemfile; then
cat <<EOF | ed Gemfile
/group :development, :test do/
.c
group :development, :test do
gem 'haml-rails'
.
w
EOF
else
cat <<EOF | ed Gemfile
\$a
group :development, :test do
gem 'haml-rails'
end
.
w
EOF
fi
bundle install
git add .
git commit -m "install haml-rails"
fi
if ! which html2haml > /dev/null; then
gem install haml --no-ri --no-rdoc
gem install hpricot --no-ri --no-rdoc
gem install ruby_parser --no-ri --no-rdoc
rbenv rehash
fi
if test -e app/views/layouts/application.html.erb; then
html2haml -e app/views/layouts/application.html.erb app/views/layouts/application.html.haml
git add .
git rm app/views/layouts/application.html.erb
git commit -m 'move app/views/layouts/application.html.erb to application.html.haml'
fi
if ! `grep -q rspec-rails Gemfile && grep -q spork-rails Gemfile`; then
if grep -q 'group :development, :test do' Gemfile; then
cat <<EOF | ed Gemfile
/group :development, :test do/
.c
group :development, :test do
gem 'rspec-rails'
gem 'spork-rails'
.
w
EOF
else
cat <<EOF | ed Gemfile
\$a
group :development, :test do
gem 'rspec-rails'
gem 'spork-rails'
end
.
w
EOF
fi
bundle install
rbenv rehash
rails g rspec:install
spork rspec --bootstrap
cat <<EOF | ed spec/spec_helper.rb
/# This file is copied to spec\/ when you run 'rails generate rspec:install'/
.,\$s/^/ /
/# This file is copied to spec\/ when you run 'rails generate rspec:install'/
.,\$d
/Spork.prefork do/
/^end/
.-1x
w
EOF
cat <<EOF | ed spec/spec_helper.rb
/Spork.each_run do/
/^end/
.i
load "#{ Rails.root}/config/routes.rb"
Dir["#{Rails.root}/app/**/*.rb"].each { |f| load f }
.
w
EOF
git add .
git commit -m "install rspec-rails and spork-rails"
fi
if ! `grep -q factory_girl_rails Gemfile`; then
if grep -q 'group :development, :test do' Gemfile; then
cat <<EOF | ed Gemfile
/group :development, :test do/
.c
group :development, :test do
gem 'factory_girl_rails'
.
w
EOF
else
cat <<EOF | ed Gemfile
\$a
group :development, :test do
gem 'factory_girl_rails'
end
.
w
EOF
fi
cat <<EOF | ed spec/spec_helper.rb
/Spork.each_run do/
/^end/
.i
FactoryGirl.reload
.
w
EOF
bundle install
git add .
git commit -m 'install factory_girl'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment