When I am in my virtualenv and it's active, the name of the environment appears in p开发者_开发问答arentheses before the normal command line prompt. It looks like: (foo-env)User:~/Development/foo-env/foo$
where foo-env
is the name of the environment. I was wondering if there was a way to make it that the command line prompt displayed something like (F)User:~/Development/foo-env/foo$
as opposed to the current display with (foo-env)
. If this is possible how would I go about doing this?
So I figured out how to do this. In the activate script the $PS1
is redefined to prepend the name of the env, in this case (foo-env)
. In order to prepend it with whatever you want you have to go into the activate
script that you run to activate the virtualenv
([yourenv]/bin/activate]
). There you change the line that that defines the new $PS1
from PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
to be whatever you want, here PS1="(F)$PS1"
.
You need to set the $PS1 environmental variable to change your prompt.
Take a look in the virtualenv config files for the setting.
See http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html for how to set it as you'd like. It sounds like you just need to replace the string foo-env
with F
.
As an alternative, use pew (Python Env Wrapper). Then your PS1
won't get mangled when you use a virtualenv, and you can set your PS1
in your .bashrc
(etc.) as usual, displaying the $VIRTUAL_ENV
if it's set. The relevant piece of mine looks like this:
# python virtual env, however it comes to be
if [ -z ${VIRTUAL_ENV+x} ]
then
VENV_NOTICE=""
else
VENV_NOTICE=" (py: $(basename "$VIRTUAL_ENV"))"
fi
PS1='whatever $VENV_NOTICE else'
精彩评论