Skip to content

Instantly share code, notes, and snippets.

View VasLem's full-sized avatar

Vassilis Lemonidis VasLem

  • UAntwerp
  • Antwerp, Belgium
View GitHub Profile
@VasLem
VasLem / .virtualenv_autoactivate.sh
Last active September 30, 2024 09:12
Made for Linux. Auto activates and deactivates Python virtual environments of a project. The requirement is that the virtual environment resides in .venv inside the root directory of the project. To use it, source it in your .bashrc.
check_for_venv() {
DIR_NAME=$PWD
VENVLOC=
while [ "$DIR_NAME" != "/" ]; do
if [ -e "$DIR_NAME/bin/python" ] && [ -e "$DIR_NAME/bin/activate" ]; then
VENVLOC="$DIR_NAME"
_VENV_NAME=$(basename $DIR_NAME)
break
elif [ -e "$DIR_NAME/.venv/bin/python" ] && [ -e "$DIR_NAME/.venv/bin/activate" ] ; then