# Irb dyamic prompt configuration

**URL:** <https://www.ruby-forum.com/t/irb-dyamic-prompt-configuration/86140>\
**Category:** Ruby\
**Created:** [February 20, 2007, 6:23am UTC](https://www.ruby-forum.com/t/irb-dyamic-prompt-configuration/86140 "2007-02-20T06:23:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamdonquixote](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/85e7bf/32.png) [@iamdonquixote](https://www.ruby-forum.com/u/iamdonquixote)\
**Post date:** [February 20, 2007, 6:23am UTC](https://www.ruby-forum.com/t/irb-dyamic-prompt-configuration/86140/1 "2007-02-20T06:23:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![iamdonquixote](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/85e7bf/32.png) [@iamdonquixote](https://www.ruby-forum.com/u/iamdonquixote)\
**Post date:** [February 20, 2007, 7:26am UTC](https://www.ruby-forum.com/t/irb-dyamic-prompt-configuration/86140/2 "2007-02-20T07:26:38Z")

</div>

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
