Skip to content

Instantly share code, notes, and snippets.

@lanmaster53
Last active May 3, 2017 13:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lanmaster53/747c634887c87187a68592dd5068a7c0 to your computer and use it in GitHub Desktop.
Save lanmaster53/747c634887c87187a68592dd5068a7c0 to your computer and use it in GitHub Desktop.
# 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