6868# path might contain stuff to expand.
6969# (it might be possible to do this in shell, but I don't know a
7070# cross-shell-safe way of doing it -wolever)
71- if echo " $WORKON_HOME " | grep -e " [$~]" > /dev/null
71+ if echo " $WORKON_HOME " | egrep -e " ( [$~]|//) " > /dev/null
7272then
7373 # This will normalize the path by:
74- # - Expanding variables (eg, $foo)
75- # - Converting ~s to complete paths (eg, ~/ to /home/brian/ and ~arthur to /home/arthur)
74+ # - Removing extra slashes (e.g., when TMPDIR ends in a slash)
75+ # - Expanding variables (e.g., $foo)
76+ # - Converting ~s to complete paths (e.g., ~/ to /home/brian/ and ~arthur to /home/arthur)
7677 WORKON_HOME=$( " $VIRTUALENVWRAPPER_PYTHON " -c " import os; print os.path.expandvars(os.path.expanduser(\" $WORKON_HOME \" ))" )
7778 export WORKON_HOME
7879fi
8182virtualenvwrapper_verify_workon_home () {
8283 if [ ! -d " $WORKON_HOME " ]
8384 then
84- [ " $1 " != " -q" ] && echo " ERROR: Virtual environments directory '$WORKON_HOME ' does not exist. Create it or set WORKON_HOME to an existing directory." >&2
85+ [ " $1 " != " -q" ] && echo " ERROR: Virtual environments directory '$WORKON_HOME ' does not exist. Create it or set WORKON_HOME to an existing directory." 1 >&2
8586 return 1
8687 fi
8788 return 0
@@ -92,20 +93,20 @@ virtualenvwrapper_verify_workon_home () {
9293# Expects 1 argument, the suffix for the new file.
9394virtualenvwrapper_tempfile () {
9495 # Note: the 'X's must come last
95- mktemp " virtualenvwrapper-$1 -XXXXXX"
96+ mktemp -t " virtualenvwrapper-$1 -XXXXXX"
9697}
9798
9899# Run the hooks
99100virtualenvwrapper_run_hook () {
100- hook_script=" $( virtualenvwrapper_tempfile hook) "
101+ typeset hook_script=" $( virtualenvwrapper_tempfile ${1} - hook) "
101102 " $VIRTUALENVWRAPPER_PYTHON " -c ' from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script " $hook_script " " $@ "
102103 result=$?
103104
104105 if [ $result -eq 0 ]
105106 then
106107 source " $hook_script "
107108 fi
108- rm -f " $hook_script " & > /dev/null
109+ rm -f " $hook_script " > /dev/null 2>&1
109110 return $result
110111}
111112
@@ -115,14 +116,14 @@ virtualenvwrapper_initialize () {
115116 virtualenvwrapper_run_hook " initialize"
116117 if [ $? -ne 0 ]
117118 then
118- echo " virtualenvwrapper.sh: Python encountered a problem. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH set properly." 1>&2
119+ echo " virtualenvwrapper.sh: Python encountered a problem. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH is set properly." 1>&2
119120 return 1
120121 fi
121122}
122123
123124# Verify that virtualenv is installed and visible
124125virtualenvwrapper_verify_virtualenv () {
125- venv=$( which virtualenv | grep -v " not found" )
126+ typeset venv=$( which virtualenv | grep -v " not found" )
126127 if [ " $venv " = " " ]
127128 then
128129 echo " ERROR: virtualenvwrapper could not find virtualenv in your path" >&2
@@ -382,7 +383,7 @@ add2virtualenv () {
382383cdsitepackages () {
383384 virtualenvwrapper_verify_workon_home || return 1
384385 virtualenvwrapper_verify_active_environment || return 1
385- site_packages=" ` virtualenvwrapper_get_site_packages_dir` "
386+ typeset site_packages=" ` virtualenvwrapper_get_site_packages_dir` "
386387 cd " $site_packages " /$1
387388}
388389
@@ -398,7 +399,7 @@ cdvirtualenv () {
398399lssitepackages () {
399400 virtualenvwrapper_verify_workon_home || return 1
400401 virtualenvwrapper_verify_active_environment || return 1
401- site_packages=" ` virtualenvwrapper_get_site_packages_dir` "
402+ typeset site_packages=" ` virtualenvwrapper_get_site_packages_dir` "
402403 ls $@ $site_packages
403404
404405 path_file=" $site_packages /virtualenv_path_extensions.pth"
@@ -427,12 +428,12 @@ cpvirtualenv() {
427428 fi
428429 if echo " $WORKON_HOME " | grep -e " /$" > /dev/null
429430 then
430- env_home=" $WORKON_HOME "
431+ typset env_home=" $WORKON_HOME "
431432 else
432- env_home=" $WORKON_HOME /"
433+ typeset env_home=" $WORKON_HOME /"
433434 fi
434- source_env=" $env_home$env_name "
435- target_env=" $env_home$new_env "
435+ typeset source_env=" $env_home$env_name "
436+ typeset target_env=" $env_home$new_env "
436437
437438 if [ ! -e " $source_env " ]
438439 then
@@ -442,12 +443,12 @@ cpvirtualenv() {
442443
443444 cp -r " $source_env " " $target_env "
444445 for script in $( ls $target_env /bin/* )
445- do
446+ do
446447 newscript=" $script -new"
447448 sed " s|$source_env |$target_env |g" < " $script " > " $newscript "
448449 mv " $newscript " " $script "
449450 chmod a+x " $script "
450- done
451+ done
451452
452453 virtualenv " $target_env " --relocatable
453454 sed " s/VIRTUAL_ENV\(.*\)$env_name /VIRTUAL_ENV\1$new_env /g" < " $source_env /bin/activate" > " $target_env /bin/activate"
0 commit comments