我定义了一个函数来检查环境变量
VIRTUAL_ENV
设置了,如果设置了,请找出当前的Python版本。
theme_python_prompt () {
if [ -v VIRTUAL_ENV ]
then
local VERSION="$(python -V)"
echo -n "%{$fg[yellow]%}î¼%{$reset_color%}:${VERSION}(%{$fg[magenta]%}$(basename ${VIRTUAL_ENV})%{$reset_color%})"
fi
}
但是,这只是输出
python -V
而不是将其存储到变量中。打印整个堆栈(
set -x
)显示以下内容:
+theme_python_prompt:1> [ -v VIRTUAL_ENV ']'
+theme_python_prompt:3> python -V
Python 2.7.15
+theme_python_prompt:3> echo ''
+theme_python_prompt:3> local VERSION=''
+theme_python_prompt:4> basename /home/hjpotter92/.virtualenvs/test-2fI9Fep8
+theme_python_prompt:4> echo -n $'%{\C-[[33m%}î¼%{\C-[[00m%}:(%{\C-[[35m%}test-2fI9Fep8%{\C-[[00m%})'
类似的函数来获取我
rbenv
信息正在正常工作,没有问题:
theme_rbenv_prompt () {
if ! type rbenv > /dev/null
then
echo -n ""
else
local VERSION="$(rbenv_prompt_info)"
[ "$VERSION" != "system" ] && echo "%{$fg_bold[red]%}î%{$reset_color%}:${VERSION} " || echo -n ""
fi
}
在哪里?
rbenv_prompt_info
来自
oh-my-zsh plugin
.