Created
May 7, 2015 07:20
-
-
Save spikeekips/7dafc620713bf9112f45 to your computer and use it in GitHub Desktop.
workspace manager for python virtualenv and golang
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
root=$(cd $(dirname ${BASH_SOURCE})/../; pwd) | |
export VIRTUALENV_GO=$root | |
export GOPATH=$VIRTUALENV_GO | |
export GOBIN=$VIRTUALENV_GO/bin | |
export PATH=$VIRTUALENV_GO/bin:$PATH |
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
ws () { | |
# get virtualenv | |
if [ ! -z ${VIRTUAL_ENV} ];then | |
VIRTUALENV=${VIRTUAL_ENV} | |
fi | |
if [ ! -z ${VIRTUALENV_GO} ];then | |
VIRTUALENV=${VIRTUALENV_GO} | |
fi | |
is_activated () { | |
if [ -z ${VIRTUALENV} ];then | |
echo 0 | |
return | |
fi | |
echo 1 | |
} | |
ws_deactivate () { | |
type deactivate &>/dev/null | |
if [ $? -eq 1 ];then | |
return | |
fi | |
if [ ! -z ${VIRTUALENV} ];then | |
cd ${VIRTUALENV} | |
deactivate | |
fi | |
} | |
# parse options | |
args=("$@") | |
newargs=("") | |
no_activate=0 | |
go_home=0 | |
for a in "${args[@]}" | |
do | |
case $a in | |
"home") | |
go_home=1 | |
return | |
;; | |
"-q") | |
ws_deactivate | |
return | |
;; | |
"-na") | |
no_activate=1 | |
;; | |
*) | |
echo "$a" | grep '^\-' &>/dev/null | |
if [ $? -eq 0 ];then | |
continue | |
fi | |
newargs+=("$a") | |
;; | |
esac | |
done | |
cd $HOME/workspace | |
project=${newargs[@]} | |
# read properties from projects.json | |
get_project_path () { | |
python <<EOF | |
import sys | |
import json | |
try : | |
_j = json.loads(file('projects.json').read()) | |
print _j.get("${project}", "${project}") | |
sys.exit(0) | |
except (TypeError, ValueError): | |
print "${project}" | |
sys.exit(0) | |
EOF | |
} | |
path=$(get_project_path) | |
if [ -z "${path}" ];then | |
if [ $(is_activated) -eq 1 ];then | |
cd ${VIRTUALENV} | |
return | |
fi | |
fi | |
ws_deactivate | |
cd $HOME/workspace/${path} | |
if [ ${no_activate} -eq 0 ];then | |
activate="$(pwd)/bin/activate" | |
if [ -f ${activate} ];then | |
source ${activate} | |
fi | |
fi | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment