How to format irb command prompt

血红的双手。 提交于 2019-11-27 02:43:04

问题


Previously I was using Ruby 1.8 and my irb command prompt used to look like this:

Air ~: irb
>> a = 1
=> 1
>> b = 2
=> 2
>> a + b
=> 3

I installed rvm (and Ruby 1.9.2) and now my irb command prompt looks like this:

Air ~: irb
ruby-1.9.2-p180 :001 > a = 1
 => 1 
ruby-1.9.2-p180 :002 > b = 2
 => 2 
ruby-1.9.2-p180 :003 > a + b
 => 3 

Is there a way to remove the ruby-1.9.2-p180 :001 from the command line?


回答1:


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.)




回答2:


In your ~/.irbrc, simply add

IRB.conf[:PROMPT_MODE] = :SIMPLE



回答3:


When you would usually run the irb command, try running irb --simple-prompt instead. That greatly shortens the prompt and makes it easier to understand.




回答4:


irb --simple-prompt

saw this in Lynda.com




回答5:


To avoid giving the prompt you wish on the command line all the time, you can configure the prompt via the ~/.irbrc config file:

$ echo "IRB.conf[:PROMPT_MODE] = :DEFAULT" > ~/.irbrc
$ irb
irb(main):001:0> quit
$ echo "IRB.conf[:PROMPT_MODE] = :SIMPLE" > ~/.irbrc
$ irb
>> quit
$ 



回答6:


See this note about IRB prompt in RVM.

Note that you can create a .irbrc file in your home folder for various settings for IRB. For example, see "Configuring the Prompt" in this document

You can also puts IRB.conf[:PROMPT_MODE] or puts IRB.conf to see all the various settings currently in effect. For example, the :PROMPT_MODE is probably set to "RVM" in your case.



来源:https://stackoverflow.com/questions/6039292/how-to-format-irb-command-prompt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!