Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

break Python virtualenv display #57

Open
HoLengZai opened this issue Aug 31, 2021 · 2 comments
Open

break Python virtualenv display #57

HoLengZai opened this issue Aug 31, 2021 · 2 comments

Comments

@HoLengZai
Copy link

Hi,

When you activate a Python virtualenv, posh-git-sh got the priority and I don't see the name of my virtual env on the prompt.
It is a bit annoying because I don't know if I am in my virtualenv or not.

I don't have this issue using the original powershell post-git version

toto@computer_name:~ $ mkdir -p ~/toto_test; cd ~/toto_test
toto@computer_name:~/toto_test $ git init
toto@computer_name:~/toto_test $ python -m venv .venv
toto@computer_name:~/toto_test $ source ./.venv/bin/activate

I should get something like that:

(.venv) toto@computer_name: ~/toto_test [main =]$

I got this instead

toto@computer_name: ~/toto_test [main =]$
@n-peugnet
Copy link

n-peugnet commented Aug 31, 2021

My workaround for this issue is to use __posh_git_echo function instead of __posh_git_ps1 in $PROMPT_COMMAND and manually removing the previous git information using sed, based on a delimiter character I added to my $PS1 previously (here >):

function prompt_command {
    PS1="$(echo $PS1 | sed 's/>.*/>/') $(__posh_git_echo)\n$ "
}
PROMPT_COMMAND=prompt_command;$PROMPT_COMMAND

My PS1 is defined like this (notice the > at the end):

PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w> '

Another advantage of this technique is that it keeps your previous PS1 customizations (if any) but keep in mind that it will break if the delimiter character appears before in the PS1, for instance in the path. It should not appear too often if you carefully choose your delimiter.

@lyze
Copy link
Owner

lyze commented Aug 31, 2021

There are also some other neat suggestions in this SO question that may help. Virtualenv modifies the shell prompt, so some elbow grease is required to make sure only at most one tool modifies PROMPT_COMMAND.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants