Skip to content

Commit 6366622

Browse files
committed
first copy
--HG-- extra : convert_revision : svn%3A98f53aa3-d424-0410-b225-a548b0275c4d/Projects/virtualenvwrapper/trunk%401349
1 parent 67c3b9b commit 6366622

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

virtualenvwrapper_bashrc

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#
2+
# $Id$
3+
#
4+
5+
#
6+
# Setup:
7+
#
8+
# 1. Add a line like "export WORKON_HOME=$HOME/.virtualenvs"
9+
# to your .bashrc.
10+
# 2. Add a line like "source /path/to/this/file/virtualenvwrapper_bashrc"
11+
# to your .bashrc.
12+
# 3. Run: source ~/.bashrc
13+
# 4. Run: workon
14+
# 5. A list of environments, empty, is printed.
15+
# 6. Run: mkvirtualenv temp
16+
# 7. Run: workon
17+
# 8. This time, the "temp" environment is included.
18+
# 9. Run: workon temp
19+
# 10. The virtual environment is activated.
20+
#
21+
22+
# Make sure there is a default value for WORKON_HOME.
23+
if [ "$WORKON_HOME" = "" ]
24+
then
25+
export WORKON_HOME="$HOME/.virtualenvs"
26+
fi
27+
28+
# Verify that the WORKON_HOME directory exists
29+
function verify_workon_home () {
30+
if [ ! -d "$WORKON_HOME" ]
31+
then
32+
echo "ERROR: $WORKON_HOME does not exist!"
33+
return 1
34+
fi
35+
return 0
36+
}
37+
38+
# Function to create a new environment, in the WORKON_HOME.
39+
function mkvirtualenv () {
40+
verify_workon_home
41+
(cd "$WORKON_HOME"; virtualenv $*)
42+
}
43+
44+
# Function to remove an environment, in the WORKON_HOME.
45+
function rmvirtualenv () {
46+
typeset env_name="$1"
47+
verify_workon_home
48+
env_dir="$WORKON_HOME/$env_name"
49+
if [ "$VIRTUAL_ENV" == "$env_dir" ]
50+
then
51+
echo "ERROR: You cannot remove the active environment."
52+
return 1
53+
fi
54+
rm -rf "$env_dir"
55+
}
56+
57+
# Function to list the available environments.
58+
function show_workon_options () {
59+
verify_workon_home
60+
ls "$WORKON_HOME" | egrep -v '*.egg' | sort
61+
}
62+
63+
# Function to list or change working virtual environments
64+
function workon () {
65+
typeset env_name="$1"
66+
if [ "$env_name" = "" ]
67+
then
68+
show_workon_options
69+
return 1
70+
fi
71+
72+
activate="$WORKON_HOME/$env_name/bin/activate"
73+
if [ ! -f "$activate" ]
74+
then
75+
echo "ERROR: No activate for $WORKON_HOME/$env_name"
76+
return 1
77+
fi
78+
source "$activate"
79+
return 0
80+
}

0 commit comments

Comments
 (0)