Skip to content

Override python's plain virtualenv prompt

The way python overrides the bash prompt is barbaric.

According to this SO answer the default change can be overridden by setting VIRTUAL_ENV_DISABLE_PROMPT=1.

The prompt information than then be obtained by this function:

function virtualenv_info(){
    # Get Virtual Env
    if [[ -n "$VIRTUAL_ENV" ]]; then
        # Strip out the path and just leave the env name
        venv="${VIRTUAL_ENV##*/}"
    else
        # In case you don't have one activated
        venv=''
    fi
    [[ -n "$venv" ]] && echo "(venv:$venv) "
}