fix autopyenv prompt
This commit is contained in:
parent
903d3575ba
commit
401b3a9591
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue