7
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rbenv のversionをpromptに表示させる

Last updated at Posted at 2016-11-30

TL;DR

  • 複数のレポジトリを行ったり来たりすると、設定しているrubyのバージョンがわからなくなることがるので promptに表示させる
  • zsh-hookで表示させるscriptを登録する
  • 色や、位置などはお好みで

script


autoload -Uz add-zsh-hook

rbenv_version () {
  local ruby_v=$(rbenv version-name)
  if [[ "`rbenv version | grep '.rbenv/version'`" = "" ]];then
    if [[ "`rbenv version | grep 'RBENV_VERSION'`" = "" ]];then
      local setting="%{$fg[green]%}[$ruby_v (local)]%{$reset_color%}"
    else
      local setting="%{$fg[blue]%}[$ruby_v (global)]%{$reset_color%}"
    fi
  else
    local setting="%{$fg[blue]%}[$ruby_v (global)]%{$reset_color%}"
  fi
  RPROMPT="$setting"
}
add-zsh-hook precmd rbenv_version

rbenv_version_prompt.jpg

7
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?