-
Notifications
You must be signed in to change notification settings - Fork 0
/
cd_into_env.sh
executable file
·36 lines (35 loc) · 1.15 KB
/
cd_into_env.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
cd(){
# TODO: there's a lot of redundant code. come up with a way to fix it.
builtin cd "$@"
# check if .python-version exists in current dir
# if exists, read venv name
if [ -e .python-version ] ; then
# save dir of .python-version
parent_dir=$PWD
env_name="`cat .python-version`"
env_path=~/venv-manager/my_venvs/$env_name
# check if no virtual env is active
if [ -z "$VIRTUAL_ENV" ] ; then
# activate venv read from .python-version
if [ -d $env_path ] ; then
source $env_path/bin/activate
fi
# parent env is active
# deactivate it, and activate current sub env
else
deactivate
if [ -d $env_path ] ; then
source $env_path/bin/activate
fi
fi
else
if [ ! -z "$VIRTUAL_ENV" ] ; then
# if virtul_env is active, check if folder is a subdir of original virtual_env
# if yes then do nothing
# else deactivate
if [[ "$PWD"/ != "$parent_dir"/* ]] ; then
deactivate
fi
fi
fi
}