darvid / zsh-poetry

🐚 Simple ZSH plugin for automatically activating and deactivating Poetry-created virtualenvs. 🐍
MIT License
75 stars 14 forks source link

Error with grep BSD version #1

Closed estyxx closed 5 years ago

estyxx commented 5 years ago

The grep installed on osx doesn't have the "-P" (Perl regex) option.

grep -V 
grep (BSD grep) 2.5.1-FreeBSD

Using sed here instead of grep should fix it:

venv=$(command poetry debug:info 2>/dev/null | sed -n "s/\* Path: +\t*\(.*\)/\1/p")
venv=${path_venv##* }

But the name of the poetry venv does not appear anyway...

darvid commented 5 years ago

ahh, good catch. I'll have to hunt down an osx machine to test with.

But the name of the poetry venv does not appear anyway...

could you elaborate a bit on this please? does it fail to activate? is VIRTUAL_ENV set/unset in a poetry project directory?

estyxx commented 5 years ago

No, The $VIRTUAL_ENV variable is empty, who should set it?

I was inside a directory with pyproject.toml, I fixed locally the petry.zsh file (as I mentioned above) to be able to run your tool... And [maybe I did not understand the purpose of this tool... sorry if I did...] I was expecting to visualize the name of the activate poetry environment in the prompt element with powerlevel9k like anaconda does... Maybe it's a feature :) or print something at least...

darvid commented 5 years ago

VIRTUAL_ENV should be set automatically after cding to a directory with a pyproject.toml file, if this plugin worked correctly and sourced the poetry bin/activate script. if it's not, then I'm guessing something went wrong with that...

this plugin doesn't actually output anything, but poetry+virtualenv itself should update your prompt when activated. I'm a powerlevel user too (👊), and the virtualenv prompt segment picks up my venv correctly, on Linux at least.

could you try maybe putting some echo statements to show the value of $venv after your modifications above? I'm curious if ${venv}/bin/activate exists? also what's your poetry version?

estyxx commented 5 years ago

Ok, I understood the problems:

  1. I removed "virtalenv" from the PROMT_ELEMENTS because I was using anaconda
  2. Poetry wasn't installed globally... -.- Definitely changing the venv grep should resolve the problem...
    venv=$(command poetry debug:info 2>/dev/null | sed -n "s/\ *\* Path:\ *\(.*\)/\1/p")
darvid commented 5 years ago

ahh, cool. thanks for the fix!