Skip to content

Instantly share code, notes, and snippets.

@tyraeltong
Created October 14, 2011 13:26
Show Gist options
  • Select an option

  • Save tyraeltong/1287091 to your computer and use it in GitHub Desktop.

Select an option

Save tyraeltong/1287091 to your computer and use it in GitHub Desktop.
setup rails development environment for a fresh mac
def write(text="")
puts text
end
def say(message, subitem=false)
write "#{subitem ? " ->" : "--"} #{message}"
end
def say_custom(tag, text)
say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}"
end
def say_recipe(name)
say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..."
end
def say_wizard(text)
say_custom(@current_recipe || 'wizrd', text)
end
def ask(text, color=nil)
say("#{text} ", color)
gets.strip
end
def ask_wizard(question)
ask "\033[1m\033[30m\033[46m" + (@current_recipe || "prompt").rjust(10) + "\033[0m\033[36m" + " #{question}\033[0m"
end
def yes_wizard?(question)
answer = ask_wizard(question + " \033[33m(y/n)\033[0m")
case answer.downcase
when "yes", 'y'
true
when "no", 'n'
false
else
yes_wizard?(question)
end
end
def no_wizard?(question)
!yes_wizard?(question)
end
def multiple_choice(question, choices)
say_custom('question', question)
values = {}
choices.each_with_index do |choice, i|
values[(i+1).to_s] = choice[1]
say_custom (i+1).to_s + ')', choice[0]
end
answer = ask_wizard("Enter your selection:") while !values.keys.include?(answer)
values[answer]
end
say_wizard "You're using Tyrael Tong's Rails dev environment setup recipes..."
config = {}
# >-----------------------[Homebrew]--------------------<
say_recipe 'homebrew'
system("ruby -e \"$(curl -fsSL https://raw.github.com/gist/323731)\"")
# >-----------------------[Git]-------------------------<
say_recipe "brew git"
system("brew install git")
# >-----------------------[Git]-------------------------<
say_recipe "brew wget"
system("brew install wget")
# >-----------------------[Zsh]-------------------------<
say_recipe "zsh"
config['set-zsh-as-shell'] = yes_wizard?("Would you like to use zsh as your default shell?")
system("brew install zsh")
system("wget --no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh")
if config['set-zsh-as-shell']
say_custom 'zsh', "Set zsh as your default shell..."
system("chsh -s /bin/zsh")
end
# >-----------------------[RVM]--------------------<
say_recipe 'rvm'
config = {}
config['install-ruby-1.9.2'] = yes_wizard?("Would you like to install Ruby 1.9.2?")
`(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer) | bash`
say_custom 'rvm', "Setting profile of shell access for rvm..."
system("echo '[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && . \"$HOME/.rvm/scripts/rvm\" # Load RVM function' >> $HOME/.bash_profile")
system("echo '[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && . \"$HOME/.rvm/scripts/rvm\" # Load RVM function' >> $HOME/.zshrc")
# system("$HOME/.rvm/scripts/rvm")
load_rvm="source ~/.bash_profile"
if config['install-ruby-1.9.2']
say_custom 'rvm', "Installing Ruby 1.9.2 via RVM..."
system("#{load_rvm} ; rvm install 1.9.2")
end
if config['install-ruby-1.9.2']
if yes_wizard?("Would you like to install Rails 3.1?")
say_custom 'rvm', "Creating a gemset for rails 3.1"
use_192 = "rvm use 1.9.2"
use_gemset = "rvm gemset use rails31"
system("#{load_rvm} ; #{use_192}")
system("#{load_rvm} ; #{use_192} ; rvm gemset create rails31")
system("#{load_rvm} ; #{use_192} ; #{use_gemset} ; gem update --system ; gem install rails -v=3.1")
end
end
say_wizard "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment