How to Format Irb Command Prompt

How to format irb command prompt

The irb man page has a section on "Customizing prompt". Here's mine for example:

IRB.conf[:PROMPT][:CUSTOM] = {
:PROMPT_I => ">> ",
:PROMPT_S => "%l>> ",
:PROMPT_C => ".. ",
:PROMPT_N => ".. ",
:RETURN => "=> %s\n"
}
IRB.conf[:PROMPT_MODE] = :CUSTOM
IRB.conf[:AUTO_INDENT] = true

To use this, add it to your ~/.irbrc file (creating it if it doesn't exist.)

Is it possible to configure the IRB prompt to change dynamically?

Here's a quick hack to get the working dir. It's sort of fragile, but it worked on ruby 1.8.7 and 1.9.2.

Set your prompt string to something like this:

"%N(%m):%03n:%i %~> ".tap {|s| def s.dup; gsub('%~', Dir.pwd); end }

The "%~" directive is not understood by irb itself, so I used it to do the replacement. This hack relies on the fact that irb calls dup to generate the prompt.

irb command line prefix remove

You can edit your ~/.irbrc file to change the prompt (command line prefix). See this answer for an example. You could put this in there to start:

IRB.conf[:PROMPT][:CUSTOM] = {:PROMPT_I => ">> "}
IRB.conf[:PROMPT_MODE] = :CUSTOM
IRB.conf[:AUTO_INDENT] = true

.irbrc is a Ruby script that irb runs when it starts up that lets you configure your prompt.

Copy paste from irb excluding prompt at start of line?

You can hold the ⌥ Option key and drag for a rectangular selection:

You can also customize IRB's prompt. Here's an example of the built-in --noprompt option which provides a blank prompt:


Entering IRB line prematurely into Terminal.. How to Resolve?

2 things I can think of off the bat: finish entering the code on the next line, or hit ctl-c and start over.

missing '= ' in ruby irb results

try

irb --prompt default

or

irb --prompt inf-ruby --readline

or this after irb starts

conf.prompt_c="%N(%m):%03n:%i* "
conf.prompt_i="%N(%m):%03n:%i> "
conf.prompt_mode=:DEFAULT
conf.prompt_n="%N(%m):%03n:%i> "
conf.prompt_s="%N(%m):%03n:%i%l "

also check irb --help it has some great help use that :)

Reset IRB Console

Type

exec($0)

in your irb console session.

How Do You Clear The IRB Console?

On Mac OS X or Linux you can use Ctrl + L to clear the IRB screen.

Ruby on Windows using Ruby irb, and how to set up RoR

In irb you can tell if your current line is unterminated doesn't start with >.

irb(main):001:0> "I'm gonna wait
irb(main):002:0" to finish this string" # The string isn't terminated
=> "I'm gonna wait\nto finish this string"
irb(main):003:0>

But more interestingly in irb it would seem that a semi-colon(;) it won't terminate the line. Since semi-colons(;) inRuby aren't necessary and are just meant to be statement separators. irb won't actually run your statements until you end one without a semi-colon. Also 1 => 1 isn't a valid Ruby statement.

irb(main):001:0> string = ""
=> ""
irb(main):002:0> string << "I'm gonna run this line\n";
irb(main):003:0* string << "Plus this line\n"
=> "I'm gonna run this line\nPlus this line\n"
irb(main):004:0> string << "Semi-colons are not cool in Ruby"
=> "I'm gonna run this line\nPlus this line\nSemi-colons are not cool in Ruby"
irb(main):005:0>

So your problem should be solved by NEVER using semi-colons in Ruby

Also all these examples were run on Windows 7 using Powershell

PS C:\Users\Justin> ruby -v
ruby 1.9.3p0 (2011-10-30) [i386-mingw32]

As Aaron mentioned the best way to get started is probably RailsInstaller. I haven't used it personally, but it looks like it does pretty much everything for you.

I use RubyInstaller and set up my Rails environment myself. RailsInstaller does all that for you.



Related Topics



Leave a reply



Submit