Skip to content

Instantly share code, notes, and snippets.

@nrh
Last active November 27, 2016 17:33
Show Gist options
  • Save nrh/1041ed4ed5ec49bf788029d7b2ce6f48 to your computer and use it in GitHub Desktop.
Save nrh/1041ed4ed5ec49bf788029d7b2ce6f48 to your computer and use it in GitHub Desktop.
bash function for python virtualenv thingies.
function venv-activate {
if [ ! -z "$1" ]; then
. $PWD/$1/bin/activate
else
_matches=($(compgen -G "*/bin/activate") $(compgen -G ".??*/bin/activate"))
if [ ${#_matches[@]} -eq 0 ]; then
echo "Environment not found."
elif [ ${#_matches[@]} -eq 1 ]; then
_env=${_matches[0]}
echo "Found $_env"
. $PWD/$_env
elif [ ${#_matches[@]} -gt 1 ]; then
echo "Multiple matches:"
for i in ${_matches[@]}; do
echo " $i"
done
fi
fi
}
alias venv-deactivate=deactivate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment