10

I created a venv like so:

python3 -m venv .venv

When I activate it, the shell prompt is changed.

antkong@konga-mbp ~/dev/my-project (git-branch-name)
$ source .venv/bin/activate
(.venv) konga-mbp:my-project antkong$

How can I keep the prompts the same?

Giacomo1968
  • 58,727
Anthony Kong
  • 5,318

1 Answers1

10

The prompt of the Bash shell is controlled by the PS1 variable.

The activate script — near the bottom — keeps its old value in the _OLD_VIRTUAL_PS1 variable before prepending it with the venv's name:

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
    _OLD_VIRTUAL_PS1="${PS1:-}"
    if [ "x(gearshift3.8) " != x ] ; then
    PS1="(gearshift3.8) ${PS1:-}"
...

Therefore, to immediately revert back to your old PS1, type:

export PS1="$_OLD_VIRTUAL_PS1"

You may edit the activate scripts and disable the above conditional block, for all future venv activations, by replacing its 1st line with this:

if false; then

If you want to disable the prompt for all subsequent venv activations (during your shell session), set some value to the variable checked at the condition of the block:

export VIRTUAL_ENV_DISABLE_PROMPT=1

Finally, if you want this behavior to persist for all your future console sessions, add the above line into your ~/.bashrc.

Giacomo1968
  • 58,727
ankostis
  • 239