[英]Enable pyenv-virtualenv prompt at terminal
I just installed pyenv and virtualenv following: https://realpython.com/intro-to-pyenv/我刚刚安装了 pyenv 和 virtualenv 如下: https://realpython.com/intro-to-pyenv/
After completing installation I was prompted with:完成安装后,系统提示我:
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior
I added export PYENV_VIRTUALENV_DISABLE_PROMPT=1
to my .bash_aliases
just to see what the behavior would be, and sure enough it removed the prompt that used to exist at the beginning of the command prompt indicating the pyenv-virtualenv version.我将
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
添加到我的.bash_aliases
只是为了查看行为是什么,并且确实删除了曾经存在于命令提示符开头的指示 pyenv-virtualenv 版本的提示符。 Used to be like:曾经是这样的:
(myenv) user@foo:~/my_project [main] $
where (myenv)
is the active environment, and [main]
is the git branch.其中
(myenv)
是活动环境, [main]
是 git 分支。
I would love to have the environment indicator back.我很想恢复环境指标。 It is very useful: I guess at some possibilities such as:
这非常有用:我猜想有一些可能性,例如:
export PYENV_VIRTUALENV_DISABLE_PROMPT=0
export PYENV_VIRTUALENV_ENABLE_PROMPT=1
But these do not return the previous behavior.但是这些不会返回以前的行为。 I have googled all over and can't figure out how to get this back.
我到处搜索,无法弄清楚如何取回它。
This answer is not useful, as it seems like a hack around the original functionality, and displays the environment always, not just when I enter (or manually activate) an environment. 这个答案没有用,因为它似乎是对原始功能的破解,并且始终显示环境,而不仅仅是在我进入(或手动激活)环境时。
Borrowing a solution from here , the following works (added to .bashrc
or .bash_aliases
):从这里借用一个解决方案,以下工作(添加到
.bashrc
或.bash_aliases
):
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
export BASE_PROMPT=$PS1
function updatePrompt {
if [[ "$(pyenv virtualenvs)" == *"* $(pyenv version-name) "* ]]; then
export PS1='($(pyenv version-name)) '$BASE_PROMPT
else
export PS1=$BASE_PROMPT
fi
}
export PROMPT_COMMAND='updatePrompt'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.