-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyVirtEnv
executable file
·59 lines (48 loc) · 1.84 KB
/
PyVirtEnv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
# Written By Woland
# A Script To Make New Python Virtual Enviorments & Install Packages
# Inside It With pip If Specified
# https://github.com/wolandark
# https://github.com/wolandark/BASH_Scripts_For_Everyone
# Help Message
if [ "$1" = "-o" ] || [ "$1" = "-h" ]; then
echo -e "\n\t[Usage]: Run the Script With \$1 And If Needed, \$2, \$3 & \$4 etc ..."
echo -e "\t Where \$1 Is The First Argument And The New Virtual Env Name"
echo -e "\t And \$2 ... Is The Name Of An Optional Package/s To Be Installed With pip Into The Virtual Env\n"
echo -e "\t[Example]: ./PyVirtEnv NewEnv PyQt5\n"
echo -e "\tYou Should Also Place This Script In Your Home Directory"
echo -e "\n\t[Setup]: "
echo -e "\t Run The Script With The [setup] As Argument To Setup Your SHELL, SH & BASH Are Supported"
echo -e "\nFor More Info Visit: https://docs.python.org/3/library/venv.html"
exit 0
fi
# Setup Argument To Echo The Function To Shellrc
if [ "$1" = "setup" ] && [ "$SHELL" = "/bin/bash" ]; then
echo 'PyEnv() { ~/PyVirtEnv "$@"; source "$1/bin/activate"; cd "$1"; }' >> ~/.bashrc
exit 0
else
if [ "$1" = "setup" ] && [ "$SHELL" = "/bin/sh" ]; then
echo 'PyEnv() { ~/PyVirtEnv "$@"; source "$1/bin/activate"; cd "$1"; }' >> ~/.shrc
exit 0
fi
fi
# Make Directory
if [ -d $1 ]; then
echo "Directory with this name exists in $PWD"
exit 0
else
mkdir $1
fi
# Setup Python Virtual Env & Source It
python3 -m venv "$1"
source "$1"/bin/activate
# Handling Arguments As Packages To Install At Once
shift
echo "Installing packages: " "$@"
pip install "$@"
# Priniting Info For The User
tput setaf 6; echo -e "\nYou Should run: source "$PWD"/"$1"/bin/activate"
tput setaf 1; echo -e "Your virtual env at "$PWD"/"$1" is ready for you!\n"
tput setaf 6; echo "Done!"
tput sgr0
exit 0