3131
3232# Normalize the directory name in case it includes
3333# relative path components.
34- WORKON_HOME=$(python -c "import os; print os.path.abspath(os.path.expandshell (os.path.expanduser(\"$pydir \")))")
34+ WORKON_HOME=$(python -c "import os; print os.path.abspath(os.path.expandvars (os.path.expanduser(\"$WORKON_HOME \")))")
3535export WORKON_HOME
3636
3737# Verify that the WORKON_HOME directory exists
@@ -46,6 +46,22 @@ function virtualenvwrapper_verify_workon_home () {
4646
4747virtualenvwrapper_verify_workon_home
4848
49+ # Verify that virtualenv is installed and visible
50+ function virtualenvwrapper_verify_virtualenv () {
51+ venv=$(which virtualenv | grep -v "not found")
52+ if [ "$venv" = "" ]
53+ then
54+ echo "ERROR: virtualenvwrapper could not find virtualenv in your path" >&2
55+ return 1
56+ fi
57+ if [ ! -e "$venv" ]
58+ then
59+ echo "ERROR: Found virtualenv in path as \"$venv\" but that does not exist" >&2
60+ return 1
61+ fi
62+ return 0
63+ }
64+
4965# Verify that the requested environment exists
5066function virtualenvwrapper_verify_workon_environment () {
5167 typeset env_name="$1"
@@ -94,6 +110,7 @@ function virtualenvwrapper_run_hook () {
94110function mkvirtualenv () {
95111 eval "envname=\$$#"
96112 virtualenvwrapper_verify_workon_home || return 1
113+ virtualenvwrapper_verify_virtualenv || return 1
97114 (cd "$WORKON_HOME" &&
98115 virtualenv "$@" &&
99116 virtualenvwrapper_run_hook "./premkvirtualenv" "$envname"
@@ -133,7 +150,7 @@ function virtualenvwrapper_show_workon_options () {
133150 # NOTE: DO NOT use ls here because colorized versions spew control characters
134151 # into the output list.
135152 # echo seems a little faster than find, even with -depth 3.
136- (cd "$WORKON_HOME"; for f in */bin/activate; do echo $f; done) | sed 's|^\./||' | sed 's|/bin/activate||' | sort
153+ (cd "$WORKON_HOME"; for f in */bin/activate; do echo $f; done) 2>/dev/null | sed 's|^\./||' | sed 's|/bin/activate||' | sort
137154# (cd "$WORKON_HOME"; find -L . -depth 3 -path '*/bin/activate') | sed 's|^\./||' | sed 's|/bin/activate||' | sort
138155}
139156
0 commit comments