Why is virtualenv not setting my terminal prompt?
Whatever is setting up your git-aware prompt is probably defining the PROMPT_COMMAND
function. Try adding this to the end of your .bashrc
file.
add_venv_info () { if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then _OLD_VIRTUAL_PS1="$PS1" if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then # special case for Aspen magic directories # see http://www.zetadev.com/software/aspen/ PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1" elif [ "$VIRTUAL_ENV" != "" ]; then PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1" fi fi export PS1}PROMPT_COMMAND=add_venv_info
What are Aspen magic directories? I have no idea; this was code copied from an activate
script to demonstrate how to use PROMPT_COMMAND
to include virtual environment information into your propmt. If they aren't relevant to your situation, you can simply add the PS1=...
assignment that you want. The only really important parts are 1) Checking VIRTUAL_ENV_DISABLE_PROMPT
and 2) making the desired assignment to PS1
.
I had the same issue, but the above solution didn't work for me.
I ended up doing this:(mind that there's an additional space to separate the (virtenv)
from the $
# Virtual ENV stuffadd_venv_info () { if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then VIRT_ENV_TXT="" if [ "x" != x ] ; then VIRT_ENV_TXT="" else if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then # special case for Aspen magic directories # see http://www.zetadev.com/software/aspen/ VIRT_ENV_TXT="[`basename \`dirname \"$VIRTUAL_ENV\"\``]" elif [ "$VIRTUAL_ENV" != "" ]; then VIRT_ENV_TXT="(`basename \"$VIRTUAL_ENV\"`)" fi fi if [ "${VIRT_ENV_TXT}" != "" ]; then echo ${VIRT_ENV_TXT}" " fi fi}# Now we construct the prompt.# in my case a bunch of lines constructing the complete PS1# somewhere call the add_venv_info function like below PS1=${PS1}"\[\$(job_color)\]\n\$(add_venv_info)\$\[${NC}\] "