Python scripts I use to manage my ssh connections, drive mounts, and other bash related things.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

  1. #!/bin/bash
  2. # virtualenv-auto-activate.sh
  3. #
  4. # Installation:
  5. # Add this line to your .bashrc or .bash-profile:
  6. #
  7. # source /path/to/virtualenv-auto-activate.sh
  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. if [ "$VIRTUAL_ENV" != "$(pwd -P)/.venv" ]; then
  31. _VENV_NAME=$(basename `pwd`)
  32. echo Activating virtualenv \"$_VENV_NAME\"...
  33. VIRTUAL_ENV_DISABLE_PROMPT=1
  34. source .venv/bin/activate
  35. _OLD_VIRTUAL_PS1="$PS1"
  36. PS1="($_VENV_NAME)$PS1"
  37. export PS1
  38. fi
  39. fi
  40. }
  41. export PROMPT_COMMAND=_virtualenv_auto_activate