Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activate when entering subdirs #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions poetry.zsh
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
#!/usr/bin/env zsh
ZSH_POETRY_AUTO_ACTIVATE=${ZSH_POETRY_AUTO_ACTIVATE:-1}
ZSH_POETRY_AUTO_DEACTIVATE=${ZSH_POETRY_AUTO_DEACTIVATE:-1}
ZSH_POETRY_OVERRIDE_SHELL=${ZSH_POETRY_OVERRIDE_SHELL:-1}

autoload -U add-zsh-hook

find-in-parents() {
_parent=$(pwd)
while [[ ${_parent} != "" && ! -e ${_parent}/${1} ]]; do
_parent=${_parent%/*}
done
echo ${_parent}
}

_zp_current_project=

_zp_check_poetry_venv() {
local venv
if [[ -z $VIRTUAL_ENV ]] && [[ -n "${_zp_current_project}" ]]; then
_zp_current_project=
fi
if [[ -f pyproject.toml ]] \
&& [[ "${PWD}" != "${_zp_current_project}" ]]; then
_proj_dir=$(find-in-parents pyproject.toml)
if [[ -n ${_proj_dir} ]] \
&& ([[ -z ${_zp_current_project} ]] \
|| [[ "${PWD}" != "${_zp_current_project}"* ]]); then
venv="$(command poetry env list --full-path | sed "s/ .*//" | head -1)"
if [[ -d "$venv" ]] && [[ "$venv" != "$VIRTUAL_ENV" ]]; then
source "$venv"/bin/activate || return $?
_zp_current_project="${PWD}"
_zp_current_project="${_proj_dir}"
return 0
fi
elif [[ -n $VIRTUAL_ENV ]] \
Expand Down