1
0
Fork 0

new virtualenvwrapper plugin

This commit is contained in:
Luca Bilke 2024-02-22 12:16:33 +01:00
parent a9585ed831
commit a02e396905
2 changed files with 37 additions and 1 deletions

View file

@ -8,7 +8,7 @@ source $ZDOTDIR/configs/aliases
source $ZDOTDIR/plugins/fzf/bindings.zsh
source $ZDOTDIR/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
[ -r /usr/bin/virtualenvwrapper_lazy.sh ] && source /usr/bin/virtualenvwrapper_lazy.sh
source $ZDOTDIR/plugins/virtualenvwrapper.plugin.zsh
for f in $ZDOTDIR/configs/autogenerated/*; do
source $f

View file

@ -0,0 +1,36 @@
. "$(which virtualenvwrapper_lazy.sh)"
type workon >/dev/null 2>&1
[ -z "$WORKON_HOME" ] || { echo "$WORKON_HOME unset!"; exit 1; }
workon_cwd() {
[ -z "$WORKON_CWD" ] && {
WORKON_CWD=1
PROJECT_ROOT="${PWD}"
}
while [ "$PROJECT_ROOT" != "/" ] && [ ! -e "$PROJECT_ROOT/.venv" ] && [ ! -d "$PROJECT_ROOT/.git" ]; do
PROJECT_ROOT="$(dirname "$PROJECT_ROOT")"
done
[ "$PROJECT_ROOT" != "/" ] && ENV_NAME="$(basename "$PROJECT_ROOT")"
[ -n "$CD_VIRTUAL_ENV" ] && [ "$ENV_NAME" != "$CD_VIRTUAL_ENV" ] && {
[ -n "$VIRTUAL_ENV" ] && deactivate
unset CD_VIRTUAL_ENV
}
[ -z "$ENV_NAME" ] && [ ! "$(realpath "$VIRTUAL_ENV")" = "$(realpath "$WORKON_HOME/$ENV_NAME")" ] && {
if [ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]; then
workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
elif [ -e "$ENV_NAME/bin/activate" ]; then
. "$ENV_NAME/bin/activate" && export CD_VIRTUAL_ENV="$ENV_NAME"
else
ENV_NAME=""
fi
}
[ -z "$ENV_NAME" ] && [ -n "$CD_VIRTUAL_ENV" ] && [ -n "$VIRTUAL_ENV" ] && deactivate && unset CD_VIRTUAL_ENV
}
autoload -U add-zsh-hook
add-zsh-hook chpwd workon_cwd
[ "$PWD" != ~ ] && workon_cwd