@@ -521,6 +521,7 @@ function rmvirtualenv {
521521
522522 # support to remove several environments
523523 typeset env_name
524+ # Must quote the parameters, as environments could have spaces in their names
524525 for env_name in " $@ "
525526 do
526527 echo " Removing $env_name ..."
@@ -559,13 +560,18 @@ function virtualenvwrapper_show_workon_options {
559560 # NOTE: DO NOT use ls or cd here because colorized versions spew control
560561 # characters into the output list.
561562 # echo seems a little faster than find, even with -depth 3.
563+ # Note that this is a little tricky, as there may be spaces in the path.
562564 #
563565 # 1. Look for environments by finding the activate scripts.
564566 # Use a subshell so we can suppress the message printed
565567 # by zsh if the glob pattern fails to match any files.
566- # 2. Strip the WORKON_HOME prefix from each name.
567- # 3. Strip the bindir/activate script suffix.
568- # 4. Format the output to show one name on a line.
568+ # This yields a single, space-separated line containing all matches.
569+ # 2. Replace the trailing newline with a space, so every
570+ # possible env has a space following it.
571+ # 3. Strip the bindir/activate script suffix, replacing it with
572+ # a slash, as that is an illegal character in a directory name.
573+ # This yields a slash-separated list of possible env names.
574+ # 4. Replace each slash with a newline to show the output one name per line.
569575 # 5. Eliminate any lines with * on them because that means there
570576 # were no envs.
571577 (virtualenvwrapper_cd " $WORKON_HOME " && echo * /$VIRTUALENVWRAPPER_ENV_BIN_DIR /activate) 2> /dev/null \
@@ -723,6 +729,8 @@ function workon {
723729 return 1
724730 elif [ " $env_name " = " ." ]
725731 then
732+ # The IFS default of breaking on whitespace causes issues if there
733+ # are spaces in the env_name, so change it.
726734 IFS=' %'
727735 env_name=" $( basename $( pwd) ) "
728736 unset IFS
@@ -885,15 +893,15 @@ function cdsitepackages {
885893 virtualenvwrapper_verify_workon_home || return 1
886894 virtualenvwrapper_verify_active_environment || return 1
887895 typeset site_packages=" ` virtualenvwrapper_get_site_packages_dir` "
888- virtualenvwrapper_cd " $site_packages " /$1
896+ virtualenvwrapper_cd " $site_packages /$1 "
889897}
890898
891899# Does a ``cd`` to the root of the currently-active virtualenv.
892900# :help:cdvirtualenv: change to the $VIRTUAL_ENV directory
893901function cdvirtualenv {
894902 virtualenvwrapper_verify_workon_home || return 1
895903 virtualenvwrapper_verify_active_environment || return 1
896- virtualenvwrapper_cd " $VIRTUAL_ENV " /$1
904+ virtualenvwrapper_cd " $VIRTUAL_ENV /$1 "
897905}
898906
899907# Shows the content of the site-packages directory of the currently-active
@@ -1293,7 +1301,9 @@ function allvirtualenv {
12931301 virtualenvwrapper_verify_workon_home || return 1
12941302 typeset d
12951303
1296- IFS=' '
1304+ # The IFS default of breaking on whitespace causes issues if there
1305+ # are spaces in the env_name, so change it.
1306+ IFS=' %'
12971307 virtualenvwrapper_show_workon_options | while read d
12981308 do
12991309 [ ! -d " $WORKON_HOME /$d " ] && continue
0 commit comments