Last active
July 18, 2016 06:32
-
-
Save cdosborn/f516ed705fcb6b867d7c58dbc34f9b6f to your computer and use it in GitHub Desktop.
A simple wrapper for virtualenv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# ve NAME creates and activates venv | |
# ve wipe remove and deactivate current venv | |
# ve wipe NAME... remove multiple venvs | |
# ve list print all venvs | |
# | |
function ve { | |
local VE_DIR="$HOME/.ve" | |
if [ ! -x "$(which virtualenv)" ]; then | |
echo "virtualenv is not installed"; | |
return; | |
fi; | |
case $1 in | |
"" ) | |
echo "ve wipe [NAME...] Erase virtual envs"; | |
echo "ve list List all virtual envs"; | |
echo "ve NAME Create or activate virtual env"; | |
;; | |
"wipe" ) | |
shift; | |
# | |
# ve wipe w/o arguments removes current venv | |
# | |
if [ "$#" -eq 0 -a -d "$VIRTUAL_ENV" ]; then | |
rm -rf "$VIRTUAL_ENV"; | |
fi; | |
# | |
# ve wipe with arguments removes each argument | |
# | |
local VENVS="$(ve list)" | |
for ENV in $@; do | |
local DIR="$VE_DIR/$ENV"; | |
if [[ "$VENVS" =~ "$ENV" ]] && [ -d "$DIR" ]; then | |
rm -rf "$DIR"; | |
fi; | |
done | |
# | |
# ve wipe deactivates an activated but deleted venv | |
# | |
if [ "$VIRTUAL_ENV" -a ! -d "$VIRTUAL_ENV" ]; then | |
deactivate; | |
fi; | |
;; | |
"list" ) | |
if [ ! -d "$VE_DIR" ]; then | |
mkdir "$VE_DIR"; | |
fi; | |
ls -1 "$VE_DIR"; | |
;; | |
* ) | |
# | |
# ve NAME deactivates, creates if necessary, then activates | |
# | |
if [ -d "$VIRTUAL_ENV" ]; then | |
deactivate; | |
fi; | |
if [ ! -d "$VE_DIR/$1" ]; then | |
virtualenv "$VE_DIR/$1"; | |
fi; | |
if [ -e "$VE_DIR/$1/bin/activate" ]; then | |
. "$VE_DIR/$1/bin/activate"; | |
fi | |
;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment