Skip to content

Instantly share code, notes, and snippets.

@Bouke
Created January 8, 2014 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bouke/8321952 to your computer and use it in GitHub Desktop.
Save Bouke/8321952 to your computer and use it in GitHub Desktop.
Python virtualenvwrapper
#!/bin/bash
# This hook is run after every virtualenv is activated.
#create project directory and cd into it
env_name="`basename \"$VIRTUAL_ENV\"`"
env_name="${env_name/-py3/}"
pwd_root="$HOME/Sites/$env_name"
if [ ! -d "$pwd_root" ] ; then
echo "Creating directory $pwd_root"
mkdir "$pwd_root"
fi
cd "$pwd_root"
#colorful env name
PS1="\[\033[33m\](`basename \"$VIRTUAL_ENV\"`)$_OLD_VIRTUAL_PS1"
@Bouke
Copy link
Author

Bouke commented Jan 8, 2014

This hook will create a folder with the same name as the virtual environment in ~/Sites/. If the name contains -py3, that's stripped from the name. This allows you to share a folder for between Python 2 and 3 virtual environments.

The last command uses some lively colors for the name of the virtual environment in your prompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment