You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
960 B
42 lines
960 B
10 years ago
|
# --- activate a virtualenv without the need of going through a series of
|
||
|
# paths
|
||
|
function venv { source $WORKON_HOME/$1/bin/activate; }
|
||
|
|
||
|
# --- create a virtualenv
|
||
|
function mkenv { virtualenv $WORKON_HOME/$1; venv $1; echo "$1" > ./.venv; }
|
||
|
|
||
|
# --- automagically load virtualenvs, based on the ".venv" file in the directory
|
||
|
|
||
|
# -- search for the ".venv" from the current directory and, if it can't be found,
|
||
|
# go through the parent directories all the way to the system root
|
||
|
function _upwards_search {
|
||
|
venv=""
|
||
|
curdir=`pwd`
|
||
|
|
||
|
while [[ `pwd` != '/' ]]; do
|
||
|
if [ -f ./.venv ]; then
|
||
|
venv=`cat ./.venv`
|
||
|
break
|
||
|
fi
|
||
|
cd ..
|
||
|
done
|
||
|
|
||
|
cd $curdir
|
||
|
echo $venv;
|
||
|
}
|
||
|
|
||
|
# -- replacement for "cd", which will check the virtualenv file
|
||
|
function _venv_cd {
|
||
|
if [ ! -f $PWD/$1 -a "$VIRTUAL_ENV." != "." ]; then
|
||
|
deactivate
|
||
|
fi;
|
||
|
\cd $1
|
||
|
venv=$(_upwards_search)
|
||
|
if [ -n $venv ]; then
|
||
|
venv $venv
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
# -- replace "cd" with our magical "cd"
|
||
|
alias cd=_venv_cd
|