Created
July 19, 2012 02:54
-
-
Save arches/3140457 to your computer and use it in GitHub Desktop.
Run a project-specific IRB config in Rails 3.1+
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
if ENV['RAILS_ENV'] | |
rails_env = ENV['RAILS_ENV'].downcase | |
elsif Rails and Rails.env | |
rails_env = Rails.env.downcase | |
end | |
if rails_env | |
current_app = "myapp" | |
black = "\[\033[0;30m\]" | |
red = "\[\033[0;31m\]" | |
green = "\[\033[0;32m\]" | |
yellow = "\[\033[0;33m\]" | |
blue = "\[\033[0;34m\]" | |
purple = "\[\033[0;35m\]" | |
cyan = "\[\033[0;36m\]" | |
reset = "\[\033[0;0m\]" | |
environment_color = case rails_env | |
when 'development' | |
green | |
when 'staging' | |
yellow | |
when 'production' | |
red | |
else | |
red | |
end | |
rails_env = {'development' => 'dev', 'staging' => 'staging', 'production' => 'prod'}.fetch(rails_env) { 'unknown' } | |
IRB.conf[:PROMPT][:RAILS_ENV] = { | |
:PROMPT_I => "#{green}#{current_app}#{environment_color}(#{rails_env})#{reset}> ", | |
:PROMPT_N => "#{green}#{current_app}#{environment_color}(#{rails_env})#{reset}> ", | |
:PROMPT_S => nil, | |
:PROMPT_C => "?> ", | |
:RETURN => "=> %s\n" | |
} | |
IRB.conf[:PROMPT_MODE] = :RAILS_ENV | |
end |
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
# Works on Heroku! | |
module MyAppName | |
class Application < Rails::Application | |
def load_console(app=self) | |
super | |
ARGV.push "-r", File.join(Rails.root, ".irbrc.rb") | |
end | |
end | |
end |
I thought about it.... Just don't know how to get the module name of the
app. Maybe I could just write a railtie? Probably not too hard, just
haven't looked.
Also, I'm having a hard time figuring out how to denote non printing
characters in such a way that they aren't counted in the prompt length by
the shell. Right now, if you type a few dozen characters and hit ctrl-u you
can see how long it thinks the prompted is.
…On Jul 19, 2012 5:34 PM, "Kerri Miller" < ***@***.***> wrote:
Make this a gem.
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/3140457
I'm on it.. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make this a gem.