MichaelAquilina / zsh-autoswitch-virtualenv

🐍 ZSH plugin to automatically switch python virtualenvs (including pipenv and poetry) as you move between directories
GNU General Public License v3.0
538 stars 84 forks source link

wrong prompt with new terminal directly drop into project #126

Closed lookis closed 3 years ago

lookis commented 4 years ago

Issue Details

  1. prompt/PS1 was not set when create a new term directly drop into the python project
  2. after 1, change to another folder will pop an wrong theme (default theme)

Please provide the following details when opening an issue:

Operating System (uname -a)

Mac 10.15.2

zsh version (zsh --version)

zsh 5.7.1 (x86_64-apple-darwin19.0)

autoswitch-virtualenv version

echo "$AUTOSWITCH_VERSION")
<your version here>

1.15.0

How is zsh-autoswitch-virtualenv installed?

Steps to reproduce the issue

gist link to your zshrc

Some more Info

virtualenv will remember previous PROMPT when "activate", but theme for oh my zsh will load later:

  1. load plugin 1.1. load autoswitch-virtualenv 1.2. load "activate" 1.3. virtualenv's activate remember system default PS1
  2. load theme 2.1 theme override "activate" PS1

//work on the project //change folder

  1. deactivate 3.1 deactivate restore wrong PS1
MichaelAquilina commented 4 years ago

@lookis I'm not sure I fully understand this bug. Would you mind posting some screenshots showing the issue to help out?

lookis commented 4 years ago

I have do a screen recording to reproduce, notice that I open 2nd terminal with shortcut: cmd+t , which i means "drop into" https://www.dropbox.com/s/u3u4eb1o35tmfuh/Screen%20Recording%202020-02-11%20at%206.49.45%20AM.mov?dl=0

lookis commented 4 years ago

Online player compress the video, you can have it downloaded and see

stegmannb commented 4 years ago

I belive I have the same issue.

Steps to reproduce:

  1. have a .venv file that links to your default environment (same one as in AUTOSWITCH_DEFAULTENV) in the home directory
  2. start a terminal
  3. zsh-autoswitch-virtualenv tells me it switched to the default venv
  4. my zsh theme/promp still shows correctly
  5. switch to a directory containing a .venv
  6. zsh-autoswitch-virtualenv switches to the correct environment
  7. my zsh theme/promp is missing - i beleive the default theme is shown
  8. when is switch back zsh-autoswitch-virtualenv still switches correctly
  9. zsh still uses the wrong theme

Here you can see that the theme stays for the first switch after starting the terminal and that it is broken after switching to a other directory with a .venv file. prompt_with_plugin

This is how it looks without the plugin: prompt_without_plugin

This only occurs when I have a .venv file in $HOME. Removing that and switching to your default venv in .zshrc is an easy workaround.

hauntsaninja commented 4 years ago

I also have this issue. I was able to fix by removing the call to check_venv that the plugin makes at load time: https://github.com/MichaelAquilina/zsh-autoswitch-virtualenv/blob/459e48d670ba1902cce68e509ebe6b569e771e91/autoswitch_virtualenv.plugin.zsh#L346 The issue here is that we load this plugin before other parts of my zshrc that set PROMPT and PATH and so on. Thus, deactivate fails to restore these, because they were set after activate. I then just call check_venv manually, towards the end of my zshrc.

I don't know if there's a good way to "defer" calls in zsh, but if you're hesitant to remove the check_venv call at load time, maybe we could make that configurable?

Edit: and now I see lookis' PR :-)

amr3k commented 3 years ago

Thanks @hauntsaninja for that fix, it works for me. Also thanks to @MichaelAquilina for this great plugin

seakayone commented 3 years ago

Thanks @hauntsaninja !

I have applied your fix and it solves my problem with losing the prompt, as well as the problem with autojump not being functional anymore.

MichaelAquilina commented 3 years ago

@hauntsaninja and everyone else in this issue. Do you still experience this bug on the latest release? (3.3.2)

seakayone commented 3 years ago

everyone else in this issue. Do you still experience this bug on the latest release? (3.3.2)

No, this issue seems to be fixed for me. Thanks.

hauntsaninja commented 3 years ago

Yay, thank you for fixing!