@@ -61,7 +61,7 @@ VIRTUALENVWRAPPER_ENV_BIN_DIR="bin"
61
61
if [ " $OS " = " Windows_NT" ] && [ " $MSYSTEM " = " MINGW32" ]
62
62
then
63
63
# Only assign this for msys, cygwin use standard Unix paths
64
- # and its own python installation
64
+ # and its own python installation
65
65
VIRTUALENVWRAPPER_ENV_BIN_DIR=" Scripts"
66
66
fi
67
67
@@ -156,7 +156,7 @@ function virtualenvwrapper_run_hook {
156
156
fi
157
157
" $VIRTUALENVWRAPPER_PYTHON " -c ' from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script " $hook_script " " $@ "
158
158
result=$?
159
-
159
+
160
160
if [ $result -eq 0 ]
161
161
then
162
162
if [ ! -f " $hook_script " ]
@@ -171,7 +171,7 @@ function virtualenvwrapper_run_hook {
171
171
return $result
172
172
}
173
173
174
- # Set up tab completion. (Adapted from Arthur Koziel's version at
174
+ # Set up tab completion. (Adapted from Arthur Koziel's version at
175
175
# http://arthurkoziel.com/2008/10/11/virtualenvwrapper-bash-completion/)
176
176
function virtualenvwrapper_setup_tab_completion {
177
177
if [ -n " $BASH " ] ; then
@@ -203,7 +203,7 @@ function virtualenvwrapper_setup_tab_completion {
203
203
_cdsitepackages_complete () {
204
204
reply=( $( cdsitepackages && ls -d ${1} * ) )
205
205
}
206
- compctl -K _virtualenvs workon rmvirtualenv cpvirtualenv showvirtualenv
206
+ compctl -K _virtualenvs workon rmvirtualenv cpvirtualenv showvirtualenv
207
207
compctl -K _cdvirtualenv_complete cdvirtualenv
208
208
compctl -K _cdsitepackages_complete cdsitepackages
209
209
fi
@@ -399,35 +399,41 @@ function mkvirtualenv {
399
399
400
400
# Remove an environment, in the WORKON_HOME.
401
401
function rmvirtualenv {
402
- typeset env_name=" $1 "
403
402
virtualenvwrapper_verify_workon_home || return 1
404
- if [ " $env_name " = " " ]
403
+ if [ ${ #@ } = 0 ]
405
404
then
406
405
echo " Please specify an enviroment." >&2
407
406
return 1
408
407
fi
409
- env_dir=" $WORKON_HOME /$env_name "
410
- if [ " $VIRTUAL_ENV " = " $env_dir " ]
411
- then
412
- echo " ERROR: You cannot remove the active environment ('$env_name ')." >&2
413
- echo " Either switch to another environment, or run 'deactivate'." >&2
414
- return 1
415
- fi
416
408
417
- # Move out of the current directory to one known to be
418
- # safe, in case we are inside the environment somewhere.
419
- typeset prior_dir=" $( pwd) "
420
- \c d " $WORKON_HOME "
409
+ # support to remove several environments
410
+ typeset env_name
411
+ for env_name in $@
412
+ do
413
+ echo " Removing $env_name ..."
414
+ typeset env_dir=" $WORKON_HOME /$env_name "
415
+ if [ " $VIRTUAL_ENV " = " $env_dir " ]
416
+ then
417
+ echo " ERROR: You cannot remove the active environment ('$env_name ')." >&2
418
+ echo " Either switch to another environment, or run 'deactivate'." >&2
419
+ return 1
420
+ fi
421
421
422
- virtualenvwrapper_run_hook " pre_rmvirtualenv" " $env_name "
423
- \r m -rf " $env_dir "
424
- virtualenvwrapper_run_hook " post_rmvirtualenv" " $env_name "
422
+ # Move out of the current directory to one known to be
423
+ # safe, in case we are inside the environment somewhere.
424
+ typeset prior_dir=" $( pwd) "
425
+ \c d " $WORKON_HOME "
425
426
426
- # If the directory we used to be in still exists, move back to it.
427
- if [ -d " $prior_dir " ]
428
- then
429
- \c d " $prior_dir "
430
- fi
427
+ virtualenvwrapper_run_hook " pre_rmvirtualenv" " $env_name "
428
+ \r m -rf " $env_dir "
429
+ virtualenvwrapper_run_hook " post_rmvirtualenv" " $env_name "
430
+
431
+ # If the directory we used to be in still exists, move back to it.
432
+ if [ -d " $prior_dir " ]
433
+ then
434
+ \c d " $prior_dir "
435
+ fi
436
+ done
431
437
}
432
438
433
439
# List the available environments.
@@ -452,9 +458,9 @@ function _lsvirtualenv_usage {
452
458
#
453
459
# Usage: lsvirtualenv [-l]
454
460
function lsvirtualenv {
455
-
461
+
456
462
typeset long_mode=true
457
- if command -v " getopts" & > /dev/null
463
+ if command -v " getopts" & > /dev/null
458
464
then
459
465
# Use getopts when possible
460
466
OPTIND=1
@@ -535,14 +541,14 @@ function workon {
535
541
536
542
virtualenvwrapper_verify_workon_home || return 1
537
543
virtualenvwrapper_verify_workon_environment $env_name || return 1
538
-
544
+
539
545
activate=" $WORKON_HOME /$env_name /$VIRTUALENVWRAPPER_ENV_BIN_DIR /activate"
540
546
if [ ! -f " $activate " ]
541
547
then
542
548
echo " ERROR: Environment '$WORKON_HOME /$env_name ' does not contain an activate script." >&2
543
549
return 1
544
550
fi
545
-
551
+
546
552
# Deactivate any current environment "destructively"
547
553
# before switching so we use our override function,
548
554
# if it exists.
@@ -554,9 +560,9 @@ function workon {
554
560
fi
555
561
556
562
virtualenvwrapper_run_hook " pre_activate" " $env_name "
557
-
563
+
558
564
source " $activate "
559
-
565
+
560
566
# Save the deactivate function from virtualenv under a different name
561
567
virtualenvwrapper_original_deactivate=` typeset -f deactivate | sed ' s/deactivate/virtualenv_deactivate/g' `
562
568
eval " $virtualenvwrapper_original_deactivate "
@@ -568,10 +574,10 @@ function workon {
568
574
# Call the local hook before the global so we can undo
569
575
# any settings made by the local postactivate first.
570
576
virtualenvwrapper_run_hook "pre_deactivate"
571
-
577
+
572
578
env_postdeactivate_hook="$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postdeactivate"
573
579
old_env=$(basename "$VIRTUAL_ENV")
574
-
580
+
575
581
# Call the original function.
576
582
virtualenv_deactivate $1
577
583
@@ -585,9 +591,9 @@ function workon {
585
591
fi
586
592
587
593
}'
588
-
594
+
589
595
virtualenvwrapper_run_hook " post_activate"
590
-
596
+
591
597
return 0
592
598
}
593
599
@@ -603,7 +609,7 @@ function virtualenvwrapper_get_python_version {
603
609
604
610
# Prints the path to the site-packages directory for the current environment.
605
611
function virtualenvwrapper_get_site_packages_dir {
606
- echo " $VIRTUAL_ENV /lib/python` virtualenvwrapper_get_python_version` /site-packages"
612
+ echo " $VIRTUAL_ENV /lib/python` virtualenvwrapper_get_python_version` /site-packages"
607
613
}
608
614
609
615
# Path management for packages outside of the virtual env.
@@ -620,15 +626,15 @@ function virtualenvwrapper_get_site_packages_dir {
620
626
function add2virtualenv {
621
627
virtualenvwrapper_verify_workon_home || return 1
622
628
virtualenvwrapper_verify_active_environment || return 1
623
-
629
+
624
630
site_packages=" ` virtualenvwrapper_get_site_packages_dir` "
625
-
631
+
626
632
if [ ! -d " ${site_packages} " ]
627
633
then
628
634
echo " ERROR: currently-active virtualenv does not appear to have a site-packages directory" >&2
629
635
return 1
630
636
fi
631
-
637
+
632
638
# Prefix with _ to ensure we are loaded as early as possible,
633
639
# and at least before easy_install.pth.
634
640
path_file=" $site_packages /_virtualenv_path_extensions.pth"
@@ -702,7 +708,7 @@ function lssitepackages {
702
708
virtualenvwrapper_verify_active_environment || return 1
703
709
typeset site_packages=" ` virtualenvwrapper_get_site_packages_dir` "
704
710
ls $@ $site_packages
705
-
711
+
706
712
path_file=" $site_packages /_virtualenv_path_extensions.pth"
707
713
if [ -f " $path_file " ]
708
714
then
@@ -749,7 +755,7 @@ function cpvirtualenv {
749
755
fi
750
756
typeset source_env=" $env_home$env_name "
751
757
typeset target_env=" $env_home$new_env "
752
-
758
+
753
759
if [ ! -e " $source_env " ]
754
760
then
755
761
echo " $env_name virtualenv doesn't exist"
@@ -768,7 +774,7 @@ function cpvirtualenv {
768
774
" $VIRTUALENVWRAPPER_VIRTUALENV " " $target_env " --relocatable
769
775
\s ed " s/VIRTUAL_ENV\(.*\)$env_name /VIRTUAL_ENV\1$new_env /g" < " $source_env /$VIRTUALENVWRAPPER_ENV_BIN_DIR /activate" > " $target_env /$VIRTUALENVWRAPPER_ENV_BIN_DIR /activate"
770
776
771
- (\c d " $WORKON_HOME " && (
777
+ (\c d " $WORKON_HOME " && (
772
778
virtualenvwrapper_run_hook " pre_cpvirtualenv" " $env_name " " $new_env " ;
773
779
virtualenvwrapper_run_hook " pre_mkvirtualenv" " $new_env "
774
780
))
@@ -797,7 +803,7 @@ function virtualenvwrapper_verify_project_home {
797
803
}
798
804
799
805
# Given a virtualenv directory and a project directory,
800
- # set the virtualenv up to be associated with the
806
+ # set the virtualenv up to be associated with the
801
807
# project
802
808
function setvirtualenvproject {
803
809
typeset venv=" $1 "
0 commit comments