direnv

augments existing shells with a new feature that can load and unload environment variables depending on the current directory.

Created: by Pradeep GowdaUpdated:Aug 30, 2024Tagged: direnv · shell .

Activate python virtualenv automatically with direnv

I used the above trick to automatically load the correct virtualenv for the btbytes directory that contains the source code of this website.

$ cat ~/btbytes/.envrc
if [ "$(uname)" = "Linux" ]; then
    HOMEPATH=/home/pradeep
else
    HOMEPATH=/Users/pradeep
fi
export VIRTUAL_ENV=$HOMEPATH/btbytes/.venv
export PATH=$HOMEPATH/btbytes/.venv/bin:$PATH