Skip to content

Instantly share code, notes, and snippets.

@paveldedik
Created January 22, 2014 10:54
Show Gist options
  • Select an option

  • Save paveldedik/8556845 to your computer and use it in GitHub Desktop.

Select an option

Save paveldedik/8556845 to your computer and use it in GitHub Desktop.
Command which activates or creates a virtual environment. It's a modification of the original command which doesn't work for me properly.
# The use_env call below is a reusable command to activate/create a new Python
# virtualenv, requiring only a single declarative line of code in your .env files.
# It only performs an action if the requested virtualenv is not the current one.
use_env() {
typeset venv
venv="$1"
if [[ "${VIRTUAL_ENV##*/}" != "$venv" ]]; then
if workon | grep -q "$venv"; then
workon "$venv"
else
echo -n "Create virtualenv \"$venv\" now? (Y/n) "
read answer
if [[ "$answer" != "n" ]]; then
mkvirtualenv "$venv"
fi
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment