1
0
Fork 0

Add autopyenv zsh plugin

This commit is contained in:
Luca Bilke 2022-08-02 14:46:25 +02:00
parent bba3cc531f
commit ecb09bdee5
2 changed files with 33 additions and 0 deletions

View File

@ -19,6 +19,7 @@ export BROWSER="librewolf"
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_CACHE_HOME="$HOME/.cache"
export PYENVS_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/pyenvs"
export XINITRC="${XDG_CONFIG_HOME:-$HOME/.config}/x11/xinitrc"
# export XAUTHORITY="$XDG_RUNTIME_DIR/Xauthority" # This line will break some DMs.
export NOTMUCH_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/notmuch-config"

View File

@ -0,0 +1,32 @@
PYENV_DIR="${PYENVS_HOME:-${XDG_DATA_HOME:-$HOME/.local/share}/pyenvs}"
function chpwd_activate(){
for pydir in $(ls $PYENV_DIR); do
if [[ $(pwd|sed -e s@/@_@g) =~ "^$pydir" ]]; then
if [ "x$VIRTUAL_ENV" != "x$PYENV_DIR/$pydir" ]; then
echo "Activating virtual env $pydir"
source "$PYENV_DIR/$pydir/bin/activate"
return
fi
fi
done
if [ "x$VIRTUAL_ENV" != "x" ]; then
echo "Deactivating virtual env $VIRTUAL_ENV"
deactivate
fi
}
function venv-here(){
envdir=$(pwd|sed -e s@/@_@g)
if [ ! -e "$PYENV_DIR/${envdir}" ]; then
echo "Creating python venv for ${envdir}.."
mkdir "$PYENV_DIR" -p
python3 -m venv "$PYENV_DIR/${envdir}"
echo "Activating virtual env ${envdir}"
source "$PYENV_DIR/${envdir}/bin/activate"
else
echo "A venv for this path already exists"
fi
}
autoload -U add-zsh-hook
add-zsh-hook chpwd chpwd_activate