1
0
Fork 0

fix autopyenv prompt

This commit is contained in:
Luca Bilke 2022-08-07 09:42:14 +02:00
parent 903d3575ba
commit 401b3a9591
1 changed files with 4 additions and 3 deletions

View File

@ -1,11 +1,12 @@
PYENV_DIR="${PYENVS_HOME:-${XDG_DATA_HOME:-$HOME/.local/share}/virtualenv}"
PS1_DEFAULT="$PS1"
PS1_PRE="${PYENV_PROMPT:- %F{yellow\}%F{reset\} }"
function chpwd_activate(){
[[ "$(pwd)" == "/" ]] && return 0
for pydir in $(ls $PYENV_DIR); do
if [[ "$(pwd|sed -e s@/@_@g|cut -c2-)" =~ "^${pydir}$" ]] || [[ "r-$(pwd|sed -e s@/@_@g|cut -c2-)" =~ "^${pydir}(_.+)?$" ]]; then
if [ "x$VIRTUAL_ENV" != "x$PYENV_DIR/$pydir" ]; then
export PS1="${PYENV_PROMPT:- %F{yellow\}%F{reset\} }$PS1"
export PS1="$PS1_PRE$PS1_DEFAULT"
export VIRTUAL_ENV_DISABLE_PROMPT=1
source "$PYENV_DIR/$pydir/bin/activate"
unset VIRTUAL_ENV_DISABLE_PROMPT
@ -28,9 +29,9 @@ function venv(){
mkdir "$PYENV_DIR" -p
python3 -m venv "$PYENV_DIR/${envdir}"
echo "Activating virtual env ${envdir}"
[[ ! $PS1 =~ "^${PYENV_PROMPT:- %F{yellow\}%F{reset\} }" ]] && export PS1="${PYENV_PROMPT:- %F{yellow\}%F{reset\} }$PS1"
export VIRTUAL_ENV_DISABLE_PROMPT=1
source "$PYENV_DIR/${envdir}/bin/activate"
# source "$PYENV_DIR/${envdir}/bin/activate" && [[ ! $PS1 =~ "^$PS1_NEW" ]] && export PS1="$PS1_PRE$PS1_DEFAULT"
source "$PYENV_DIR/${envdir}/bin/activate" && export PS1="$PS1_PRE$PS1_DEFAULT"
unset VIRTUAL_ENV_DISABLE_PROMPT
else
echo "A venv for this path already exists"