Hi,

On Tuesday 20 February 2007 06:23, Rob Coeur wrote:
> 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
-- 
pub 1024D/8D2787EF  723C 7CA3 3C19 2ACE  6E20 9CC1 9956 EB3C 8D27 87EF