Last active
August 2, 2024 17:28
-
-
Save lanmaster53/747c634887c87187a68592dd5068a7c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# other stuff here | |
# derivative of https://github.com/lojikil/dotfiles/blob/master/.bashrc#L33 | |
# create virtualenv management functions | |
function venv-activate() { | |
# always activate a local venv if available | |
if [ -d "$(pwd)/venv" ] | |
then | |
echo "local virtualenv activated (venv)." | |
# ...but warn if a global venv by the given name exists | |
if [ "$1" != "" -a -d "$HOME/.venv/$1" ] | |
then | |
echo "existing global virtualenv ignored ($1)." | |
fi | |
source "$(pwd)/venv/bin/activate" | |
elif [ "$1" != "" -a -d "$HOME/.venv/$1" ] | |
then | |
echo "virtualenv activated ($1)." | |
source "$HOME/.venv/$1/bin/activate" | |
else | |
echo "invalid virtualenv ($1)." | |
fi | |
} | |
function venv-create() { | |
# only create global venvs | |
if [ "$1" != "" -a ! -d "$HOME/.venv/$1" ] | |
then | |
# create a venv using a specific python version | |
if [ "$2" != "" ] | |
then | |
virtualenv -p "$2" "$HOME/.venv/$1" || echo "virtualenv creation failed."; return | |
else | |
virtualenv "$HOME/.venv/$1" | |
fi | |
echo "virtualenv created ($1)." | |
source "$HOME/.venv/$1/bin/activate" | |
else | |
echo "virtualenv already exists ($1)." | |
fi | |
} | |
function venv-list() { | |
if [ -d "$(pwd)/venv" ] | |
then | |
echo "venv (local)" | |
fi | |
ls "$HOME/.venv/" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment