Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #!/bin/bash
  2. # virtualenv-auto-activate.bash
  3. #
  4. # Installation:
  5. # Add this line to your .bashrc or .bash-profile:
  6. #
  7. # source /path/to/virtualenv-auto-activate.bash
  8. #
  9. # Go to your project folder, run "virtualenv .venv", so your project folder
  10. # has a .venv folder at the top level, next to your version control directory.
  11. # For example:
  12. # .
  13. # ├── .git
  14. # │ ├── HEAD
  15. # │ ├── config
  16. # │ ├── description
  17. # │ ├── hooks
  18. # │ ├── info
  19. # │ ├── objects
  20. # │ └── refs
  21. # └── .venv
  22. # ├── bin
  23. # ├── include
  24. # └── lib
  25. #
  26. # The virtualenv will be activated automatically when you enter the directory.
  27. _virtualenv_auto_activate() {
  28. if [ -e ".venv" ]; then
  29. # Check to see if already activated to avoid redundant activating
  30. DIR="$(pwd -P)/.venv"
  31. # Make sure if .venv is a symlink itself, we look up VIRTUAL_ENV appropriately
  32. READLINK="$(readlink $DIR)"
  33. READLINK=${READLINK%/}
  34. #echo $VIRTUAL_ENV
  35. #echo $DIR
  36. #echo $READLINK
  37.  
  38. if [ "$VIRTUAL_ENV" != "$DIR" ] && ([ "$VIRTUAL_ENV" != "$READLINK" ] || [ "$VIRTUAL_ENV" == "" ]); then
  39. _VENV_NAME=$(basename `pwd`)
  40. echo Activating virtualenv \"$_VENV_NAME\"...
  41. VIRTUAL_ENV_DISABLE_PROMPT=1
  42. source .venv/bin/activate
  43. _OLD_VIRTUAL_PS1="$PS1"
  44. PS1="($_VENV_NAME) $PS1"
  45. export PS1
  46. fi
  47. fi
  48. }
  49.  
  50. export PROMPT_COMMAND="_virtualenv_auto_activate; $PROMPT_COMMAND"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement