Created
August 13, 2017 00:25
-
-
Save pankaj28843/4c138edd17f62456aa7de29555475cf9 to your computer and use it in GitHub Desktop.
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 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