Autoenv is super! But, my terminal has gotten a bit slower because autoenv calls workon every time I cd from one directory to another beneath the autoenv root. How can I customize my .env file so that workon is only called when I initially enter the directory?
Asked
Active
Viewed 672 times
2 Answers
2
I have this in my .env file:
type deactivate &>/dev/null || source venv/bin/activate
Check if the environment is activated. If not, activate the environment otherwise do nothing.

N. Mauchle
- 494
- 1
- 7
- 20
1
If you have multiple projects, each with its own virtualenv, and you want to switch automatically between virtualenvs when you cd
into the project folders (and of course make sure workon
is only called when necessary) then you'll need some more logic in your .env
file:
venv=venv
currentvenv=""
if [[ $VIRTUAL_ENV != "" ]]
then
# Strip out the path and just leave the env name
currentvenv="${VIRTUAL_ENV##*/}"
fi
if [[ "$currentvenv" != "$venv" ]]
then
echo "Switching to environment: $venv"
workon $venv
#else
# echo "Already on environment $venv"
fi