Last active
May 18, 2016 08:38
-
-
Save fpytloun/8597814508adf3548dda4a418e5483c5 to your computer and use it in GitHub Desktop.
Simple virtualenv manager
This file contains hidden or 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