Skip to content

Commit 31729be

Browse files
support to remove several environments at once
1 parent c662a59 commit 31729be

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

virtualenvwrapper.sh

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -399,35 +399,41 @@ function mkvirtualenv {
399399

400400
# Remove an environment, in the WORKON_HOME.
401401
function rmvirtualenv {
402-
typeset env_name="$1"
403402
virtualenvwrapper_verify_workon_home || return 1
404-
if [ "$env_name" = "" ]
403+
if [ ${#@} = 0 ]
405404
then
406405
echo "Please specify an enviroment." >&2
407406
return 1
408407
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
416408

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-
\cd "$WORKON_HOME"
409+
# support to remove several environments
410+
typeset env_name
411+
for env_name in $@
412+
do
413+
echo "Erasing $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
421421

422-
virtualenvwrapper_run_hook "pre_rmvirtualenv" "$env_name"
423-
\rm -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+
\cd "$WORKON_HOME"
425426

426-
# If the directory we used to be in still exists, move back to it.
427-
if [ -d "$prior_dir" ]
428-
then
429-
\cd "$prior_dir"
430-
fi
427+
virtualenvwrapper_run_hook "pre_rmvirtualenv" "$env_name"
428+
\rm -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+
\cd "$prior_dir"
435+
fi
436+
done
431437
}
432438

433439
# List the available environments.

0 commit comments

Comments
 (0)