Browse Source

Create virtualenv-auto-activate.sh

I don't remember where I got this script or I would provide credit. Useful if you use virtualenv.
pull/10/head
Josh Clements 5 years ago
committed by GitHub
parent
commit
f3a9220d81
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 0 deletions
  1. +43
    -0
      virtualenv-auto-activate.sh

+ 43
- 0
virtualenv-auto-activate.sh View File

@ -0,0 +1,43 @@
#!/bin/bash
# virtualenv-auto-activate.sh
#
# Installation:
# Add this line to your .bashrc or .bash-profile:
#
# source /path/to/virtualenv-auto-activate.sh
#
# Go to your project folder, run "virtualenv .venv", so your project folder
# has a .venv folder at the top level, next to your version control directory.
# For example:
# .
# ├── .git
# │ ├── HEAD
# │ ├── config
# │ ├── description
# │ ├── hooks
# │ ├── info
# │ ├── objects
# │ └── refs
# └── .venv
# ├── bin
# ├── include
# └── lib
#
# The virtualenv will be activated automatically when you enter the directory.
_virtualenv_auto_activate() {
if [ -e ".venv" ]; then
# Check to see if already activated to avoid redundant activating
if [ "$VIRTUAL_ENV" != "$(pwd -P)/.venv" ]; then
_VENV_NAME=$(basename `pwd`)
echo Activating virtualenv \"$_VENV_NAME\"...
VIRTUAL_ENV_DISABLE_PROMPT=1
source .venv/bin/activate
_OLD_VIRTUAL_PS1="$PS1"
PS1="($_VENV_NAME)$PS1"
export PS1
fi
fi
}
export PROMPT_COMMAND=_virtualenv_auto_activate

Loading…
Cancel
Save