bash 如何在终端提示中显示 RVM 当前的 Ruby 和 gemset?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4328538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I display RVM's current Ruby and gemset in the Terminal prompt?
提问by rda3000
I'm using rvm-prompt. It seems the interpreter, the version, the patchlevel, and the gemset should all displayed by default.
我正在使用rvm-prompt。似乎解释器、版本、补丁级别和 gemset 都应该默认显示。
If I call the prompt, it accurately returns the current ruby and gemset:
如果我调用提示,它会准确返回当前的 ruby 和 gemset:
$ rvm-prompt
ruby-1.8.7-p302@rails125
But my gemset isn't reflected in my prompt:
但是我的 gemset 没有反映在我的提示中:
ruby-1.8.7-p302 MacBook:~ subpixel$
I tried calling the gemset explicitly in .bash_profile with:
我尝试在 .bash_profile 中显式调用 gemset:
PS1="$(~/.rvm/bin/rvm-prompt i v p g) $PS1"
but it doesn't change the prompt.
但它不会改变提示。
采纳答案by Kris Robison
If you look at the documentation for rvm-prompt, at the bottom of the page you'll find the following:
如果您查看rvm-prompt的文档,您会在页面底部找到以下内容:
ps1_functions
Recently there has been a pair programming session that turned out a useful bit of prompt setting code. It now resides in contrib/ so you can require it in your profiles as follows after sourcing RVM itself.
source "$rvm_path/contrib/ps1_functions"Immediately after that you can customize your prompt by adding the following line
ps1_setThere is an article and screen cast associated with this in the community resources section.
ps1_functions
最近有一个结对编程会话,结果发现了一个有用的提示设置代码。它现在驻留在 contrib/ 中,因此您可以在采购 RVM 本身后按如下方式在您的配置文件中使用它。
source "$rvm_path/contrib/ps1_functions"紧接着,您可以通过添加以下行来自定义提示
ps1_set在社区资源部分有一篇与此相关的文章和屏幕截图。
I copied the ps1_functions file, changed it to suit my needs and source that in my .bash_profile. Then I just have a line that calls
我复制了 ps1_functions 文件,对其进行了更改以满足我的需要,并在我的 .bash_profile 中提供了该文件。然后我只有一条电话线
ps1_set
Now my prompt changes when I change gemsets
现在,当我更改 gemsets 时,我的提示会更改
回答by the Tin Man
You might have discovered a bug, because I see the same behavior. I'd recommend running it past RVM's author. You can find his email address by running rvm -v.
您可能已经发现了一个错误,因为我看到了相同的行为。我建议通过 RVM 的作者运行它。您可以通过运行找到他的电子邮件地址rvm -v。

