Last active
May 28, 2016 09:22
-
-
Save fpytloun/46766dbf942b03eaf3db to your computer and use it in GitHub Desktop.
Simple Python virtualenv wrapper
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
#!/bin/bash | |
VENV_HOME=${VENV_HOME:-$HOME/virtualenv} | |
SHELL=${SHELL:-/bin/zsh} | |
exit_err() { | |
echo "[ERROR] $1" 1>&2 | |
exit 1 | |
} | |
activate() { | |
[ ! -f $VENV_HOME/$1/bin/activate ] && exit_err "Virtualenv $1 not found" | |
source $VENV_HOME/$1/bin/activate | |
} | |
case $1 in | |
list) | |
for i in $VENV_HOME/*; do | |
basename $i | |
done | |
;; | |
run) | |
prog="$3" | |
args=$(echo $*|sed -e "s/$prog//g" -e "s/run//g") | |
activate "$2" | |
exec $prog $args | |
;; | |
create) | |
virtualenv "$VENV_HOME/$2" || exit_error "Virtualenv creation failed" | |
echo "[INFO] Created virtualenv $2" | |
;; | |
*) | |
activate "$1" | |
echo "[INFO] Activated virtualenv $1" | |
exec $SHELL | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment