RVM 在 ZSH 中显示 Ruby 版本

RVM showing Ruby version in ZSH

我刚刚安装了 rvm 以使用 概述的方法升级 ruby。安装后,我的 zsh 实例现在始终显示 rvm:ruby-2.3.0,如图所示:

我不希望它出现,但我找不到它的设置位置,有什么想法吗?挺烦人的。

谢谢!

Your prompt is set in a .zsh-theme file that is specified in your .zshrc file in your home directory.

更换主题:

如果您想将提示更改为已有提示,请使用您喜欢的文本编辑器打开 .zshrc 文件。您可以在 ~/.zshrc 中找到您的 .zshrc。当您打开该文件时,您会看到一行看起来像这样的行:ZSH_THEME="gallois"。 (看起来你用的是 gallois)

如果您想更改整个提示,您应该更改这一行。例如,将此从 ZSH_THEME="gallois" 更改为 ZSH_THEME="dallas" 以更改为先前存在的 dallas 主题。单击 here 以获取所有默认主题及其外观的列表。这些主题位于 ~/.oh-my-zsh/themes.

然后您应该 运行 . ~/.zshrc 获取 zsh,您将看到新提示。

正在编辑 gallois 主题删除正确的提示

这些主题位于 ~/.oh-my-zsh/themes。我建议复制 gallois.zsh-theme 文件并制作一些其他文件,如 yourname.zsh-theme。在主题文件中,您可以通过删除此评论下方的行来完全删除正确的提示:

# Combine it all into a final right-side prompt
RPS1='$(git_custom_status)$(ruby_prompt_info) $EPS1'

您可能也应该从主题文件中删除它:

# RVM component of prompt
ZSH_THEME_RVM_PROMPT_PREFIX="%{$fg[red]%}["
ZSH_THEME_RVM_PROMPT_SUFFIX="]%{$reset_color%}"

#Customized git status, oh-my-zsh currently does not allow render dirty status before branch
git_custom_status() {
  local cb=$(git_current_branch)
  if [ -n "$cb" ]; then
    echo "$(parse_git_dirty)%{$fg_bold[yellow]%}$(work_in_progress)%{$reset_color%}$ZSH_THEME_GIT_PROMPT_PREFIX$(git_current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX"
  fi
}

请记住,这也会从您的提示中删除有关 git 存储库的任何描述。然后你应该 运行 . ~/.zshrc 到 source zsh 你会看到新的提示。

编辑 gallois 主题以仅删除 ruby 提示

这些主题位于 ~/.oh-my-zsh/themes。我建议复制 gallois.zsh-theme 文件并制作一些其他文件,如 yourname.zsh-theme。在主题文件中,您可以通过删除此行的一部分来删除 rvm 提示:

# Combine it all into a final right-side prompt
RPS1='$(git_custom_status)$(ruby_prompt_info) $EPS1'

如果您只是删除 $(ruby_prompt_info) 部分,使其看起来像这样:

# Combine it all into a final right-side prompt
RPS1='$(git_custom_status) $EPS1'

然后你可以跳到最后,只删除提示的rvm部分。我还建议删除这些行以避免使主题文件混乱:

# RVM component of prompt
ZSH_THEME_RVM_PROMPT_PREFIX="%{$fg[red]%}["
ZSH_THEME_RVM_PROMPT_SUFFIX="]%{$reset_color%}"

然后您应该 运行 . ~/.zshrc 获取 zsh,您将看到新提示。

另一种隐藏 ruby 版本信息的方法是覆盖 ruby_prompt_info() 函数,用于确定提示中包含的内容。

为此,编辑您的 ~/.zshrc 并在 $HOME/.rvm/scripts/rvm 已获取后添加以下内容:

# hide ruby version from ps1
function ruby_prompt_info() { echo '' }

如果你和我一样,因为 powerlevel10k 主题的这个问题而来到这里,请执行以下操作:

  1. 打开~/.p10k.zsh

  2. 找到行:

    rvm                     # ruby version from rvm (https://rvm.io)
    
  3. 注释掉:

    # rvm                     # ruby version from rvm (https://rvm.io)
    
  4. 打开一个新终端