Skip to content

Instantly share code, notes, and snippets.

@awbacker
Created March 16, 2015 08:45
Show Gist options
  • Save awbacker/2f3eaf1f1766914dd499 to your computer and use it in GitHub Desktop.
Save awbacker/2f3eaf1f1766914dd499 to your computer and use it in GitHub Desktop.
Simple script to load a python virtual env from either ./venv/, a '.venv' file, or a global venv directory
venvnow ()
{
venv_default_root=~/dev/venvs;
cur_dir=`pwd`;
if [ -d venv ]; then
echo " - found local ./venv/, using that";
source ./venv/bin/activate;
return 0;
fi;
if [ -f '.venv' ]; then
venv_name=$(<.venv);
echo " - using .venv file : $venv_default_root/$venv_name";
source $venv_default_root/$venv_name/bin/activate;
return 0;
fi;
venv_name=$(basename "$cur_dir");
if [ -d $venv_default_root/$venv_name ]; then
echo " - using current dir name: {root:$venv_default_root}/$venv_name";
source $venv_default_root/$venv_name/bin/activate;
return 0;
fi;
echo " - unable to set venv"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment