autoenv.plugin.zsh 964 B

1234567891011121314151617181920212223242526272829
  1. # Activates autoenv or reports its failure
  2. if ! source $HOME/.autoenv/activate.sh 2>/dev/null; then
  3. echo '-------- AUTOENV ---------'
  4. echo 'Could not find ~/.autoenv/activate.sh.'
  5. echo 'Please check if autoenv is correctly installed.'
  6. echo 'In the meantime the autoenv plugin is DISABLED.'
  7. echo '--------------------------'
  8. return 1
  9. fi
  10. # The use_env call below is a reusable command to activate/create a new Python
  11. # virtualenv, requiring only a single declarative line of code in your .env files.
  12. # It only performs an action if the requested virtualenv is not the current one.
  13. use_env() {
  14. typeset venv
  15. venv="$1"
  16. if [[ "${VIRTUAL_ENV:t}" != "$venv" ]]; then
  17. if workon | grep -q "$venv"; then
  18. workon "$venv"
  19. else
  20. echo -n "Create virtualenv $venv now? (Yn) "
  21. read answer
  22. if [[ "$answer" == "Y" ]]; then
  23. mkvirtualenv "$venv"
  24. fi
  25. fi
  26. fi
  27. }