Support pipenv in virtual_env item (#170)

Co-authored-by: William Brown <Will@WillJBrown.com>
This commit is contained in:
Ilan Cosman 2021-07-08 11:27:43 -07:00
parent 6c82bd249e
commit 0c5ba87d56
2 changed files with 11 additions and 4 deletions

View File

@ -1,6 +1,10 @@
function _tide_item_virtual_env
set -l split_virtual_env (string split '/' "$VIRTUAL_ENV") &&
if contains -- $split_virtual_env[-1] virtualenv venv .venv env # avoid generic names
set -l split_virtual_env (string split / "$VIRTUAL_ENV") &&
if test $split_virtual_env[-2] = virtualenvs
# pipenv $VIRTUAL_ENV looks like /home/ilan/.local/share/virtualenvs/pipenv_project-EwRYuc3l
# Detect whether we are using pipenv by looking for virtualenvs. If so, remove the hash at the end.
_tide_print_item virtual_env $tide_virtual_env_icon' ' (string split -r -m1 - "$split_virtual_env[-1]")[1]
else if contains -- $split_virtual_env[-1] virtualenv venv .venv env # avoid generic names
_tide_print_item virtual_env $tide_virtual_env_icon' ' $split_virtual_env[-2]
else
_tide_print_item virtual_env $tide_virtual_env_icon' ' $split_virtual_env[-1]

View File

@ -9,8 +9,11 @@ set -lx tide_virtual_env_icon ''
set -lx VIRTUAL_ENV
_virtual_env # CHECK:
set -lx VIRTUAL_ENV ~/python_project/non-generic-name
set -lx VIRTUAL_ENV /home/ilan/python_project/non-generic-name
_virtual_env # CHECK:  non-generic-name
set -lx VIRTUAL_ENV ~/python_project/venv
set -lx VIRTUAL_ENV /home/ilan/python_project/venv
_virtual_env # CHECK:  python_project
set -lx VIRTUAL_ENV /home/ilan/.local/share/virtualenvs/pipenv_project-EwRYuc3l
_virtual_env # CHECK:  pipenv_project