Skip to content

Instantly share code, notes, and snippets.

@Hubro
Created June 13, 2012 13:28
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 Hubro/2924031 to your computer and use it in GitHub Desktop.
Save Hubro/2924031 to your computer and use it in GitHub Desktop.
Python virtual environment selector
function pyenv() {
VIRTUALENVS_PATH=~/pyenvs
# Procure env name. If it was supplied in an argument, use that
if [[ "$1" != "" ]]
then
VIRTUALENV_NAME=$1
else
# Otherwise prompt the user for it
VIRTUALENV_NAME=""
echo "Python virtual environment selector"
echo "Options: $(ls -h -C $VIRTUALENVS_PATH)"
read -p "Virtualenv name: " VIRTUALENV_NAME
fi
# Generate path
VIRTUALENV_PATH=$VIRTUALENVS_PATH/$VIRTUALENV_NAME/bin/activate
# Check if the virtual environment with this name exists
if [[ -f "$VIRTUALENV_PATH" ]]
then
# If yes, activate it it
source $VIRTUALENVS_PATH/$VIRTUALENV_NAME/bin/activate
echo "Activated virtual environment \"$VIRTUALENV_NAME\""
else
# Otherwise echo that it doesn't exist
echo "Virtual environment \"$VIRTUALENV_NAME\" not found"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment