Skip to content

Instantly share code, notes, and snippets.

@danielk333
Created November 9, 2021 12:55
Show Gist options
  • Save danielk333/4f94152488f4db5449055ad1a2490799 to your computer and use it in GitHub Desktop.
Save danielk333/4f94152488f4db5449055ad1a2490799 to your computer and use it in GitHub Desktop.
Venv tools in bash
activate () {
source ~/venvs/$1/bin/activate
}
lazyvenv () {
name=$(basename $(pwd))
if [ -d ~/venvs/$name ]
then
activate $name
else
echo "No venv found: creating venv"
venv
if [ -d ~/venvs/$name ]
then
activate $name
fi
fi
}
venv () {
if [ -z $1 ]
then
venv_target=$(basename $(pwd))
else
venv_target=$1
fi
echo "New venv target=$venv_target"
if [ -d ~/venvs/$venv_target ]
then
echo "Folder '~/venvs/$venv_target' exists, choose a different name for new venv"
else
python -m venv ~/venvs/$venv_target
echo "Created virtualenv $venv_target"
fi
}
venvs () {
for dr in ~/venvs/*
do
echo "$dr | python $(cat $dr/pyvenv.cfg | grep version)"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment