You should not be using this code
local ruby_version=''
if which rvm-prompt &> /dev/null; then
ruby_version="$(rvm-prompt i v g)"
else
if which rbenv &> /dev/null; then
ruby_version="$(rbenv version | sed -e "s/ (set.*$//")"
fi
fi
directly in zshrc: it won’t update ruby_version variable when switching to another project. You can change it to
function ruby_version()
{
if which rvm-prompt &> /dev/null; then
rvm-prompt i v g
else
if which rbenv &> /dev/null; then
rbenv version | sed -e "s/ (set.*$//"
fi
fi
}
and change ${ruby_version}
in your prompt to $(ruby_version)
. Or, if you are sure you don’t need checking this on each prompt (it will slow things down) you can use
function _update_ruby_version()
{
typeset -g ruby_version=''
if which rvm-prompt &> /dev/null; then
ruby_version="$(rvm-prompt i v g)"
rvm-prompt i v g
else
if which rbenv &> /dev/null; then
ruby_version="$(rbenv version | sed -e "s/ (set.*$//")"
fi
fi
}
chpwd_functions+=(_update_ruby_version)
, it will update ruby_version only when you change current directory. Also note that your code is misleading: local ruby_version=''
that is put directly into zshrc is equivalent to typeset -g ruby_version=''
or just plain ruby_version=''
which defines global, but not exported variable. There are no file-local variables in zsh (except for autoload files that actually represent functions).