posh-git-sh
posh-git-sh copied to clipboard
break Python virtualenv display
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 =]$
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.
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
.