forked from yml/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_workon.sh
executable file
·51 lines (40 loc) · 953 Bytes
/
_workon.sh
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
#!/bin/bash
workon_usage () {
echo "Usage: workon <project lookup>"
echo "Project lookup can be a project name or a path."
}
# Test if an argument is given else print the usage help text
if [ -z $1 ]
then
workon_usage
return 1
fi
echo "Deactivating the current virtual env"
# Deactivate any current environment "destructively"
# before switching so we use our override function,
# if it exists.
type deactivate >/dev/null 2>&1
if [ $? -eq 0 ]
then
deactivate
unset -f deactivate >/dev/null 2>&1
fi
OUTPUT=`python ~/.workon.py $1`
OIFS=$IFS
set -- $OUTPUT
IFS=","; declare -a Array=($*)
IFS=$OIFS
#echo "output $OUTPUT"
echo "${Array[@]}"
PROJECT_DIR=${Array[0]}
ACTIVATION_FILE=${Array[1]}
echo "Project dir $PROJECT_DIR"
echo "activation file $ACTIVATION_FILE"
if [ -d $PROJECT_DIR ]
then
cd $PROJECT_DIR
fi
if [ -f $ACTIVATION_FILE ]
then
source $ACTIVATION_FILE
fi