93ae53d07560e0492121e9f8b46fe763786b2ae1

Author
sungminoh <smoh2044@gmail.com>
Committer
sungminoh <smoh2044@gmail.com>
Date

Message

If there is pipenv virtualenv, activate it.

Diff

 1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
 2index d412e66dc24dc9eab614621d607c75146e48dce9..7f88a0b19316ea1db8dc303ba0be827ad9406526 100644
 3--- a/autoswitch_virtualenv.plugin.zsh
 4+++ b/autoswitch_virtualenv.plugin.zsh
 5@@ -16,6 +16,19 @@ if ! type workon > /dev/null; then
 6     printf "\n"
 7 fi
 8 
 9+
10+function _print_python_version() {
11+   # For some reason python --version writes to stderr
12+   if type python > /dev/null; then
13+       printf "[%s]\n" "$(python --version 2>&1)"
14+   elif type python3 > /dev/null; then
15+       printf "[%s]\n" "$(python3 --version 2>&1)"
16+   else
17+       printf "Unable to find python installed on this machine"
18+    fi
19+}
20+
21+
22 function _maybeworkon() {
23   if [[ -z "$VIRTUAL_ENV" || "$1" != "$(basename $VIRTUAL_ENV)" ]]; then
24      if [ -z "$AUTOSWITCH_SILENT" ]; then
25@@ -25,14 +38,22 @@ function _maybeworkon() {
26      workon "$1"
27 
28      if [ -z "$AUTOSWITCH_SILENT" ]; then
29-       # For some reason python --version writes to stderr
30-       if type python > /dev/null; then
31-           printf "[%s]\n" "$(python --version 2>&1)"
32-       elif type python3 > /dev/null; then
33-           printf "[%s]\n" "$(python3 --version 2>&1)"
34-       else
35-           printf "Unable to find python installed on this machine"
36-        fi
37+        _print_python_version
38+     fi
39+  fi
40+}
41+
42+
43+function _maybepipenv() {
44+  if [[ -z $VIRTUAL_ENV ]]; then
45+     if [ -z "$AUTOSWITCH_SILENT" ]; then
46+        printf "Switching pipenv: %s  " $(basename $(pipenv --venv))
47+     fi
48+
49+     . $(pipenv --venv)/bin/activate
50+
51+     if [ -z "$AUTOSWITCH_SILENT" ]; then
52+        _print_python_version
53      fi
54   fi
55 }
56@@ -94,6 +115,8 @@ function check_venv()
57 
58         if [[ -n "$SWITCH_TO" ]]; then
59           _maybeworkon "$SWITCH_TO"
60+        elif [[ -n `pipenv --venv 2>/dev/null` ]]; then
61+          _maybepipenv
62         else
63           _default_venv
64         fi