Skip to content

Instantly share code, notes, and snippets.

@yashasolutions
Created March 11, 2024 10:01
Show Gist options
  • Save yashasolutions/4f2e499822b275bc4d74dbb0dc52f68f to your computer and use it in GitHub Desktop.
Save yashasolutions/4f2e499822b275bc4d74dbb0dc52f68f to your computer and use it in GitHub Desktop.
venv - create & load virtual environment
# add to your .bashrc
# for quick project setup
function venv () {
# if project name is given
# create a new venv with the project name
# else create default venv
if [ -n "$1" ]; then
python3 -m venv .venv/$1
elif [ ! -d .venv ]; then
python3 -m venv .venv
fi
# activate the venv
# if .venv has more than one subdirectory, load regular venv
# else load the project venv
if [ $(ls -l .venv/ | grep -c ^d) -gt 1 ]; then
source .venv/bin/activate
else
source .venv/$(ls .venv/)/bin/activate
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment