Quantcast
Channel: すぱぶろ
Viewing all articles
Browse latest Browse all 30

ZSH プロンプトに rbenv version を表示する

$
0
0

rbenv versionを使用して表示させていたけど、若干動作が重かったので書き換えた。.ruby-versionが存在する場合は、そのバージョンを表示します。またそのバージョンがインストールされていない場合は {?}を表示します。

f:id:superbrothers:20130618010701p:plain

以下のスクリプトを ~/.zsh.d以下など適当な場所に置いて、.zshrcsource ~/.zsh.d/rbenv.rbのように読み込んでください。

# Allow for functions in the prompt.setopt PROMPT_SUBST

autoload -U colors && colors

if`which rbenv >/dev/null 2>&1`&& [ -z "$RBENV_ROOT" ]; thenexport RBENV_ROOT=`rbenv root`fi

rbenv_version() {
    if [ -n "$RBENV_ROOT" ]; then
        VERSION=''
        NOTFOUND=''if [ -r .ruby-version ]; then
            VERSION=`cat .ruby-version`
            ls "${RBENV_ROOT}/versions"| egrep "^$VERSION$">/dev/null 2>&1|| NOTFOUND='{?}'else
            VERSION=`cat "${RBENV_ROOT}/version"`fiecho"%{$fg[red]%}[$VERSION]$NOTFOUND%{$reset_color%}"fi
}

R?RROMPTで使います

RPROMPT="$(rbenv_version)"

Viewing all articles
Browse latest Browse all 30

Trending Articles