Forum: Ruby on Rails script/console custom prompt

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jeroen H. (Guest)
on 2006-03-08 14:34
(Received via mailing list)

I'm not able to use a custom prompt with script/console. I can't seem to
change the prompt once I'm inside irb. I can only change by passing in
the --prompt arg to irb. However, it seems script/console has the simple
  prompt hardcoded in the script. I hacked the script a little and it
seems to work, but I'm sure there is a more elegant way to do it.

irb = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'

require 'optparse'
options = { :sandbox => false, :irb => irb, :prompt => 'simple' } do |opt|
   opt.banner = "Usage: console [environment] [options]"
   opt.on('-s', '--sandbox', 'Rollback database modifications on exit.')
{ |options[:sandbox]| }
   opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |options[:irb]|
   opt.on("--prompt=[]", 'Use a different prompt for irb.') {
|options[:prompt]| }

libs =  " -r irb/completion"
libs << " -r #{RAILS_ROOT}/config/environment"
libs << " -r console_sandbox" if options[:sandbox]

ENV['RAILS_ENV'] = ARGV.first || 'development'
if options[:sandbox]
   puts "Loading #{ENV['RAILS_ENV']} environment in sandbox."
   puts "Any modifications you make will be rolled back on exit."
   puts "Loading #{ENV['RAILS_ENV']} environment."
exec "#{options[:irb]} #{libs} --prompt-mode #{options[:prompt]}"
This topic is locked and can not be replied to.