Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function create_virtualenv(){
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
project_name=$(basename "$(pwd)");
project_dir=$(pwd);
virtualenv_dir="$HOME/.virtualenvs/$project_name";
virtualenv_dir=${1:-$virtualenv_dir};
if [ -d "$virtualenv_dir" ]; then
echo "${YELLOW}virtualenv alreay exists at \"$virtualenv_dir\".${YELLOW}"
return
fi
# ensure parent directory exists
parent_dir=$(dirname "$virtualenv_dir");
if [ ! -d "$parent_dir" ]; then
mkdir -p "$parent_dir";
fi
python3.6 -m venv "$virtualenv_dir";
if [ ! -d "$virtualenv_dir" ]; then
echo "${RED}virtualenv creation failed.${RED}"
return
fi
echo "$project_dir" > "$virtualenv_dir/.project"
echo "${GREEN}virtualenv created successfuly at \"$virtualenv_dir\".${GREEN}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment