Forum: Ruby on Rails script/console custom prompt

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B9a732fc30c32098347a0177c75ee27b?d=identicon&s=25 Jeroen Houben (Guest)
on 2006-03-08 13:34
(Received via mailing list)
Hi,

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.
Anyway:

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

require 'optparse'
options = { :sandbox => false, :irb => irb, :prompt => 'simple' }
OptionParser.new 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]| }
   opt.parse!(ARGV)
end

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."
else
   puts "Loading #{ENV['RAILS_ENV']} environment."
end
exec "#{options[:irb]} #{libs} --prompt-mode #{options[:prompt]}"
This topic is locked and can not be replied to.