Last active
May 26, 2020 09:30
-
-
Save ErikDeBruijn/9c84602e1426171621299ad691e44772 to your computer and use it in GitHub Desktop.
IRB
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
IRB.conf[:SAVE_HISTORY] = 2000 | |
IRB.conf[:HISTORY_FILE] = '~/.irb-history' | |
def app_prompt | |
rails_klass = Rails.application.class | |
app_name = | |
if rails_klass.respond_to? :module_parent | |
rails_klass.module_parent | |
else | |
rails_klass.parent | |
end | |
"\033[1;34m#{app_name.name}\033[0m" | |
end | |
# target log path for irb history | |
def log_path | |
rails_root = Rails.root | |
"#{rails_root}/log/.irb-save-history" | |
end | |
def env_prompt | |
case Rails.env | |
when "development" | |
"\033[0;32mdevelopment\033[0m" | |
when "production" | |
"\033[0;31mproduction\033[0m" | |
else | |
"\033[0;33m#{Rails.env}\033[0m" | |
end | |
end | |
if defined?(Rails) | |
IRB.conf[:HISTORY_FILE] = FileUtils.touch(log_path).join | |
IRB.conf[:PROMPT] ||= {} | |
prompt = "#{app_prompt}[#{env_prompt}]:%03n " | |
IRB.conf[:PROMPT][:RAILS_EMOJI] = { | |
:PROMPT_I => "#{prompt}\u{1F601} > ", | |
:PROMPT_N => "#{prompt}\u{1F609} > ", | |
:PROMPT_S => "#{prompt}\u{1F606} > ", | |
:PROMPT_C => "#{prompt}\u{1F605} > ", | |
:RETURN => " => %s\n" | |
} | |
IRB.conf[:PROMPT_MODE] = :RAILS_EMOJI | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment