Skip to content

Customizable venv prompt prefix and suffix #144203

@bitterfox

Description

@bitterfox

Feature or enhancement

Proposal:

In venv activate PS1 is updated with the fixed format.

Some user like me doesn't like such format for some reason.

For my case, I'd like to keep empty line between the previous output and the current prompt like

[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% python --version
Python 3.14.2

[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% 

If I enable venv, it breaks my preference like

(.python.venv.default.3.14.2) 
[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% python --version
Python 3.14.2
(.python.venv.default.3.14.2) 
[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% 

I want to keep empty like between previous output and commands like

(.python.venv.default.3.14.2) 
[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% python --version
Python 3.14.2

(.python.venv.default.3.14.2) 
[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% 

This can be easily achieved keeping the compatibility by taking prefix and suffix for venv name in activate to set PS1 instaed of current "(" and ") ".

It makes someone to use explain venv name as their preferred way like

(Python env: /home/<...>/.venv)
[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% python --version
Python 3.14.2

(Python env: /home/<...>/.venv) 
[/tmp]                                                                                                                                                                                                                                                                                                                                                                                                                                  
<username>@<hostname>% 

with

# Auto activate .venv in the new dir
function chpwd() {
    if [[ -d "`pwd`/.venv" ]]; then
        VIRTUAL_ENV_PROMPT_PREFIX="
(Python env: `pwd`/" source `pwd`/.venv/bin/activate
    fi
}

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-venvRelated to the venv moduletype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions