mirror of
https://github.com/artizirk/dotfiles.git
synced 2024-11-24 17:01:00 +02:00
Add support for auto activating python venv on cd
This commit is contained in:
parent
c94f56b78b
commit
f57023e701
19
.zshrc
19
.zshrc
@ -57,7 +57,24 @@ hash -d milrem=~/code/milrem # shorten dir name in prompt
|
|||||||
|
|
||||||
# Enable or disable python virtual env
|
# Enable or disable python virtual env
|
||||||
function chpwd_auto_python_venv() {
|
function chpwd_auto_python_venv() {
|
||||||
return 0
|
local venv_dir
|
||||||
|
local cur_dir="${PWD}"
|
||||||
|
while [[ "${cur_dir}" != / ]]; do
|
||||||
|
if [[ -f "${cur_dir}/venv/bin/activate" ]]; then
|
||||||
|
venv_dir="${cur_dir}/venv"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
# :P does `realpath(3)`
|
||||||
|
# :h removes 1 trailing pathname component
|
||||||
|
cur_dir="${cur_dir:P:h}"
|
||||||
|
done
|
||||||
|
if [[ -z "${VIRTUAL_ENV}" ]] && [[ -n "${venv_dir}" ]]; then
|
||||||
|
# we found venv dir that is not yet activated
|
||||||
|
source "${venv_dir}"/bin/activate
|
||||||
|
elif [[ -z "${venv_dir}" ]] && [[ -n "${VIRTUAL_ENV}" ]]; then
|
||||||
|
# we have activated virtual env but we cant find venv folder anymore
|
||||||
|
deactivate
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
chpwd_functions+=(chpwd_auto_python_venv)
|
chpwd_functions+=(chpwd_auto_python_venv)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user