python / python/cpython

Customizable venv prompt prefix and suffix

Đang mở
#144,203 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

stdlib topic-venv type-feature
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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
  • gh-144205

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với script kích hoạt venv được đề cập trong đề xuất và xem lại cách script hiện đặt PS1. So sánh hành vi được yêu cầu đối với tiền tố và hậu tố có thể cấu hình với phần công việc được liên kết trong gh-144205; hoàn thành nghĩa là vẫn giữ mặc định hiện có đồng thời cho phép định dạng prompt được minh họa trong các ví dụ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
tooling
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.