-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathS64_virtualenv
51 lines (44 loc) · 1.11 KB
/
S64_virtualenv
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
#!/bin/zsh
VIRTUAL_ENV_DISABLE_PROMPT=True
function active_virtualenv() {
if [ -z "$VIRTUAL_ENV" ]; then
# not in a virtualenv
return
fi
basename "$VIRTUAL_ENV"
}
function enclosing_virtualenv() {
if ! which walkup > /dev/null; then
return
fi
local virtualenv="$(walkup bin/activate)"
if [ -z "$virtualenv" ]; then
# not in a virtualenv
return
fi
basename $(grep VIRTUAL_ENV= "$virtualenv"/bin/activate | sed -E 's/VIRTUAL_ENV="(.*)"$/\1/')
}
function act() {
if [ -n "$1" ]; then
if [ ! -d "$1" ]; then
echo "act: $1 no such directory"
return 1
fi
if [ ! -e "$1/bin/activate" ]; then
echo "act: $1 is not a virtualenv"
return 1
fi
if which deactivate > /dev/null; then
deactivate
fi
cd "$1"
source bin/activate
else
local virtualenv="$(walkup bin/activate)"
if [ $? -eq 1 ]; then
echo "act: not in a virtualenv"
return 1
fi
source "$virtualenv"/bin/activate
fi
}