Created
June 13, 2012 13:28
-
-
Save Hubro/2924031 to your computer and use it in GitHub Desktop.
Python virtual environment selector
This file contains hidden or 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
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