1
0
Fork 0

add PYENV_PROMPT variable

This commit is contained in:
Luca Bilke 2022-08-05 09:35:02 +02:00
parent 682fea021d
commit 2b49467e98
No known key found for this signature in database
GPG Key ID: 7B77C51E8C779E75
2 changed files with 9 additions and 4 deletions

View File

@ -64,6 +64,9 @@ export MOZ_USE_XINPUT2="1" # Mozilla smooth scrolling/touchpads.
export AWT_TOOLKIT="MToolkit wmname LG3D" #May have to install wmname
export _JAVA_AWT_WM_NONREPARENTING=1 # Fix for Java applications in dwm
export ANSIBLE_NOCOWS=1 # Stop those fucking cows in Ansible
export VIRTUAL_ENV_DISABLE_PROMPT=1
export PYENV_PROMPT=" %F{yellow\}%F{reset\} "
# This is the list for lf icons:
export LF_ICONS="\

View File

@ -1,19 +1,20 @@
PYENV_DIR="${PYENVS_HOME:-${XDG_DATA_HOME:-$HOME/.local/share}/virtualenv}"
PS1_DEFAULT="$PS1"
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=" %F{yellow}%F{reset} $PS1"
export PS1="${PYENV_PROMPT:- %F{yellow\}%F{reset\} }$PS1"
export VIRTUAL_ENV_DISABLE_PROMPT=1
source "$PYENV_DIR/$pydir/bin/activate"
unset VIRTUAL_ENV_DISABLE_PROMPT
fi
return
fi
done
if [ "x$VIRTUAL_ENV" != "x" ]; then
unset VIRTUAL_ENV_DISABLE_PROMPT
export PS1="${PS1:3}"
export PS1="$PS1_DEFAULT"
deactivate
fi
}
@ -27,9 +28,10 @@ function venv(){
mkdir "$PYENV_DIR" -p
python3 -m venv "$PYENV_DIR/${envdir}"
echo "Activating virtual env ${envdir}"
[[ ! ${PS1:0:3} == "  " ]] && export PS1="$PS1"
[[ ! $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"
unset VIRTUAL_ENV_DISABLE_PROMPT
else
echo "A venv for this path already exists"
fi