-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvnv
executable file
·153 lines (143 loc) · 3.34 KB
/
vnv
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#bin/bash
#GLOBAL VARS
GLOBAL_ENV_DIR=$HOME/.envs
MANAGER=`cat $GLOBAL_ENV_DIR/.vars/manager`
#FUNCTIONS
function printhelp {
printf """
Usage: vnv <command> argument
General Commands:
-c <virtual_env>, --create <virtual_env> Creates a virtual environment.
-a <virtual_env>, --activate <virtual_env> Activates a virtual environment.
-rm <virtual_env>, --remove <virtual_env> Removes a virtual environment from the directory.
-d, --deactivate Deactivates the current virtual environment.
-ls List all available virtual environments.
-cp <virtual_env> <new_virtual_env> Copies an existing virtual environment to a new one.
-h, --help Shows help for commands.
Settings:
manager Allows toggle of virtual environment manager
"""
}
function activate {
ENV_PATH=$GLOBAL_ENV_DIR/$1
if [ -z $ENV_PATH ]; then
echo "Please provide the name of the virtual environment you want to activate"
elif [ -e "$ENV_PATH" ]; then
source $ENV_PATH/bin/activate
else
echo "$1 is not a valid virtual environment"
fi
}
function make {
if [ -z $1 ]; then
echo "Please add a name for your virtual environment"
else
if [ $MANAGER = "python_venv" ]; then
python -m venv $HOME/.envs/$1
elif [ $MANAGER = "virtualenv" ]; then
virtualenv $HOME/.envs/$1
fi
fi
}
function remove {
ENV_PATH=$GLOBAL_ENV_DIR/$1
if [ -z $1 ]; then
echo "add a name for your virtual environment"
elif [ -e "$ENV_PATH" ]; then
rm -r $ENV_PATH
echo "removed $1 from virtual environments"
else
echo "$1 is not a valid virtual environment"
fi
}
function copy {
ENV_PATH_1=$GLOBAL_ENV_DIR/$1
ENV_PATH_2=$GLOBAL_ENV_DIR/$2
if [ -z $1 ]; then
echo "add a name for your virtual environment you want to copy from"
elif [ -z $2 ]; then
echo "add a name of a virtual environment you want to copy to"
elif [ -e "$ENV_PATH_1" ]; then
cp -r $ENV_PATH_1 $ENV_PATH_2
else
echo "$1 is not a valid virtual environment"
fi
}
function switch_manager {
echo $1 > $GLOBAL_ENV_DIR/.vars/manager
echo "Your manager is now: $1"
}
function switch_manager_menu {
printf """Your current manager is:
$MANAGER
Choose the number of the
virutal environment manager
you would like to use:
"""
select num in "virtualenv" "python_venv"; do
case $num in
virtualenv ) MANAGER="virtualenv"
switch_manager $MANAGER
break;;
python_venv ) MANAGER="python_venv"
switch_manager $MANAGER
break;;
* ) echo "Please enter a valid number"
esac
done
}
for arg in "$@"
do
case $arg in
-h|--help)
printhelp
shift
;;
-ls)
ls $GLOBAL_ENV_DIR
shift
;;
-c=*|--create=*)
NAME=${arg#*=}
make $NAME
shift
;;
-c|--create)
NAME=$2
make $NAME
shift
;;
-rm=*|--remove=*)
NAME=${arg#*=}
remove $NAME
shift
;;
-rm|--remove)
NAME=$2
remove $NAME
shift
;;
-a=*|--activate=*)
VIRTUAL_ENV=${arg#*=}
activate $VIRTUAL_ENV
shift
;;
-a|--activate)
VIRTUAL_ENV=$2
activate $VIRTUAL_ENV
shift
;;
-d|--deactivate)
deactivate
shift
;;
-cp)
copy $2 $3
shift
;;
manager)
switch_manager_menu
shift
;;
esac
done