I want to write a small script to source my virtualenv (for a Python project) directory. When I am somewhere inside my project directory, I know that the "venv" directory for my virtual environment is in a directory that is one of the ancestors of my current directory.
I want to write a shell script that will source venv/bin/activate
and its effect should persist outside this shell script. This is not happening right now.
Here's my code:
#!/bin/bash
#set -x
while [ $PWD != "/" ]; do
#echo $PWD
if [ -d "venv" ]; then
echo "venv found in $PWD. Sourcing."
source venv/bin/activate
break
else
cd ..
fi
done
Why does it not work right now, and how can I fix it?
EDIT:
If it helps, the contents of venv/bin/activate are here: http://pastebin.com/TZ40brsq It is generated by the virtualenv tool (generally used with Python projects).