irb dyamic prompt configuration

R

Rob Coeur

Hi new to ruby here. Currently I am spending alot of time playing around
on irb.
I am able to set up the prompt to my liking with a .irbc file however, I
would like the prompt to update based upon my working directory. A *sh
style prompt like : [hostname:/home/don/scripts].

How can I do this?

thanks

rob
 
M

Marcello Barnaba

Hi,

Hi new to ruby here. Currently I am spending alot of time playing around
on irb.
I am able to set up the prompt to my liking with a .irbc file however, I
would like the prompt to update based upon my working directory. A *sh
style prompt like : [hostname:/home/don/scripts].

How can I do this?

something on the lines of

cwd = Proc.new { Dir.getwd + "| %N(%m):%03n:%i> " }
cwd.instance_eval do alias :dup :call end

IRB::conf[:pROMPT][:CWD] = {
:pROMPT_C=>nil,
:AUTO_INDENT=>true,
:RETURN=>"%s\n",
:pROMPT_I=>cwd,
:pROMPT_N=>nil,
:pROMPT_S=>nil
}
IRB::conf[:pROMPT_MODE] = :CWD

in ~/.irbrc

the key here is that irb calls .dup when building the prompt string (look
in /usr/lib/ruby/1.8/irb.rb at line 265).

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top