RVM showing Ruby version in ZSH
Asked Answered
P

4

8

I just installed rvm to upgrade ruby using the method outlined here. After installation my zsh instance now always displays rvm:ruby-2.3.0, as per this image:

enter image description here

I'd rather it not appear but I'm having trouble finding where it's set, any thoughts? It's pretty annoying.

Thanks!

Perorate answered 26/8, 2016 at 15:26 Comment(0)
F
6

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

Changing to another theme:

If you want to change your prompt to a preexisting one, open your .zshrc file with your favorite text editor. Your can find your .zshrc in ~/.zshrc. When you open that file you will see a line that looks something like this: ZSH_THEME="gallois". (It looks like you're using gallois)

This is the line that you should change if you want to change your entire prompt. For example, change your this from ZSH_THEME="gallois" to ZSH_THEME="dallas" to change to the preexisting dallas theme. Click here For a list of all the default themes and what they look like. These themes are located in ~/.oh-my-zsh/themes.

You should then run . ~/.zshrc to source zsh and you will see the new prompt.

Editing the gallois theme to remove the right prompt

These themes are located in ~/.oh-my-zsh/themes. I would recommend copying the gallois.zsh-theme file and making some other file like yourname.zsh-theme. In the theme file you can remove the right prompt entirely by removing the line below this comment:

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

You should probably remove this from the theme file as well for good measure:

# 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
}

Keep in mind, this will also remove any descriptions about git repos from your prompt. You should then run . ~/.zshrc to source zsh and you will see the new prompt.

Editing the gallois theme to only remove the ruby prompt

These themes are located in ~/.oh-my-zsh/themes. I would recommend copying the gallois.zsh-theme file and making some other file like yourname.zsh-theme. In the theme file you can remove just the rvm prompt by removing a portion of this line:

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

If you just remove the $(ruby_prompt_info) portion so that it looks like this:

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

Then you can skip to the end and only remove the rvm portion of the prompt. I would also recommend removing these lines to avoid cluttering the theme file:

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

You should then run . ~/.zshrc to source zsh and you will see the new prompt.

Foolscap answered 11/11, 2016 at 0:7 Comment(1)
if, like me, you were going nuts making changes to your theme file that were not reflected in the actual shell, check to see if your theme is being loaded from a custom folder instead of the themes folder.Fogle
C
15

If, like me, you ended up here because of this problem with the powerlevel10k theme, do the following to disable the rvm segment:

  1. Open ~/.p10k.zsh

  2. Find the line:

    rvm                     # ruby version from rvm (https://rvm.io)
    
  3. Comment it out:

    # rvm                     # ruby version from rvm (https://rvm.io)
    
  4. Open a new terminal

Crucifixion answered 3/5, 2021 at 20:30 Comment(1)
my codespaces in github all of a sudden were showing the ruby version, so thanks for the pro tip here to comment this line out.Twentieth
R
9

Another way to hide the ruby version information is to override the ruby_prompt_info() function used to determine what gets included in the prompt.

To do this, edit your ~/.zshrc and add the following after $HOME/.rvm/scripts/rvm has been sourced:

# hide ruby version from ps1
function ruby_prompt_info() { echo '' }
Rajewski answered 16/5, 2019 at 15:4 Comment(2)
This is the way.Survey
Modifying the theme just gives me the ick. I added another answer based on yours too, in case you don't want to outright disable it.Survey
F
6

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

Changing to another theme:

If you want to change your prompt to a preexisting one, open your .zshrc file with your favorite text editor. Your can find your .zshrc in ~/.zshrc. When you open that file you will see a line that looks something like this: ZSH_THEME="gallois". (It looks like you're using gallois)

This is the line that you should change if you want to change your entire prompt. For example, change your this from ZSH_THEME="gallois" to ZSH_THEME="dallas" to change to the preexisting dallas theme. Click here For a list of all the default themes and what they look like. These themes are located in ~/.oh-my-zsh/themes.

You should then run . ~/.zshrc to source zsh and you will see the new prompt.

Editing the gallois theme to remove the right prompt

These themes are located in ~/.oh-my-zsh/themes. I would recommend copying the gallois.zsh-theme file and making some other file like yourname.zsh-theme. In the theme file you can remove the right prompt entirely by removing the line below this comment:

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

You should probably remove this from the theme file as well for good measure:

# 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
}

Keep in mind, this will also remove any descriptions about git repos from your prompt. You should then run . ~/.zshrc to source zsh and you will see the new prompt.

Editing the gallois theme to only remove the ruby prompt

These themes are located in ~/.oh-my-zsh/themes. I would recommend copying the gallois.zsh-theme file and making some other file like yourname.zsh-theme. In the theme file you can remove just the rvm prompt by removing a portion of this line:

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

If you just remove the $(ruby_prompt_info) portion so that it looks like this:

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

Then you can skip to the end and only remove the rvm portion of the prompt. I would also recommend removing these lines to avoid cluttering the theme file:

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

You should then run . ~/.zshrc to source zsh and you will see the new prompt.

Foolscap answered 11/11, 2016 at 0:7 Comment(1)
if, like me, you were going nuts making changes to your theme file that were not reflected in the actual shell, check to see if your theme is being loaded from a custom folder instead of the themes folder.Fogle
S
0

Building on @Keith Hughitt's answer:

You can make the ruby version conditional on the existence on an .rvnrc file if you like. That's what I did:

# I want to modify ruby_prompt_info function to only show the ruby version when inside a
# dir with a .rvmrc file
# First I need to save the original function, this requires eval to get the
# function declaration before I override it, otherwise it becomes cyclic
eval "__ruby_prompt_info() { $(declare -f ruby_prompt_info | sed '1d;$d') }"
# Now I can override to wrap the original function in a check for .rvmrc
function ruby_prompt_info() {
  if [[ -f .rvmrc ]]; then
    __ruby_prompt_info
  fi
}
Survey answered 21/8 at 20:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.