autoenv.plugin.zsh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Activates autoenv or reports its failure
  2. () {
  3. if ! type autoenv_init >/dev/null; then
  4. for d (~/.autoenv ~/.local/bin /usr/local/opt/autoenv /usr/local/bin); do
  5. if [[ -e $d/activate.sh ]]; then
  6. autoenv_dir=$d
  7. break
  8. fi
  9. done
  10. if [[ -z $autoenv_dir ]]; then
  11. cat <<END >&2
  12. -------- AUTOENV ---------
  13. Could not locate autoenv installation.
  14. Please check if autoenv is correctly installed.
  15. In the meantime the autoenv plugin is DISABLED.
  16. --------------------------
  17. END
  18. return 1
  19. fi
  20. source $autoenv_dir/activate.sh
  21. fi
  22. }
  23. [[ $? != 0 ]] && return $?
  24. # The use_env call below is a reusable command to activate/create a new Python
  25. # virtualenv, requiring only a single declarative line of code in your .env files.
  26. # It only performs an action if the requested virtualenv is not the current one.
  27. use_env() {
  28. typeset venv
  29. venv="$1"
  30. if [[ "${VIRTUAL_ENV:t}" != "$venv" ]]; then
  31. if workon | grep -q "$venv"; then
  32. workon "$venv"
  33. else
  34. echo -n "Create virtualenv $venv now? (Yn) "
  35. read answer
  36. if [[ "$answer" == "Y" ]]; then
  37. mkvirtualenv "$venv"
  38. fi
  39. fi
  40. fi
  41. }