e5b59c08a441ab56a03c513e54ffc4f6fb56ef48

Author
Michael Aquilina <michaelaquilina@gmail.com>
Committer
Michael Aquilina <michaelaquilina@gmail.com>
Date

Message

Add AUTOSWITCH_SILENT option and rename AUTOSWITCH_DEFAULTENV

Diff

 1diff --git a/README.md b/README.md
 2index f36daada9d2b57615ebfd2b2a4438dba29d1ef98..c7eceff475d13ddb232a3e0ccb7f8df5affcc81f 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -5,8 +5,8 @@ Simple ZSH plugin that switches python virtualenvs automatically as you move bet
 6 
 7 Simply create a `.venv` file with the name of the virtualenv you want to automatically switch to
 8 when you move into the directory. Moving out of the directory will automatically switch back to the
 9-default python virtual environment - set by `DEFAULT_VIRTUALENV` environment variable. If
10-`DEFAULT_VIRTUALENV` has not been set, then moving to a directory without a `.venv` file will simply
11+default python virtual environment - set by `AUTOSWITCH_DEFAULTENV` environment variable. If
12+`AUTOSWITCH_DEFAULTENV` has not been set, then moving to a directory without a `.venv` file will simply
13 deactivate any currently active virtualenv.
14 
15 NOTE that the virutalenv you specify in `.venv` must already exist.
16@@ -33,11 +33,11 @@ Installing from Antigen is super easy! Just add the following line to your `.zsh
17 ```
18 antigen bundle MichaelAquilina/zsh-autoswitch-virtualenv
19 ```
20-if you want to set a default virtual environment then you can also export `DEFAULT_VIRTUALENV` in
21+if you want to set a default virtual environment then you can also export `AUTOSWITCH_DEFAULTENV` in
22 your `.zshrc` file.
23 
24 ```
25-export DEFAULT_VIRTUALENV="mydefaultenv"
26+export AUTOSWITCH_DEFAULTENV="mydefaultenv"
27 antigen bundle MichaelAquilina/zsh-autoswitch-virtualenv
28 ```
29 
30@@ -56,7 +56,7 @@ $ cd my-python-project
31 Switching virtualenv: my-python-project  [Python 3.4.3+]
32 $
33 ```
34-If you have set the `DEFAULT_VIRTUALENV` environment variable, exiting that directory will switch
35+If you have set the `AUTOSWITCH_DEFAULTENV` environment variable, exiting that directory will switch
36 back to the value set.
37 ```
38 $ cd ..
39@@ -65,3 +65,9 @@ $
40 ```
41 Otherwise, `deactivate` will simply be called on the virtualenv to switch back to the global
42 python environment.
43+
44+Options
45+-------
46+
47+Right now the only option available is to prevent verbose messages from being displayed when moving
48+between directories. You can do this by setting "AUTOSWITCH_SILENT" to a non-empty value.
49diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
50index 276eefebab1c253a9e831dd9f98c81450dc4d920..95d3fc4832c3b6e28953327f6df1e5709c3670fd 100644
51--- a/autoswitch_virtualenv.plugin.zsh
52+++ b/autoswitch_virtualenv.plugin.zsh
53@@ -4,10 +4,16 @@ function precmd() {
54 
55 function maybeworkon() {
56   if [ "$1" != "$(basename $VIRTUAL_ENV)" ]; then
57-     printf "Switching virtualenv: %s  " $1
58+     if [ -z "$AUTOSWITCH_SILENT" ]; then
59+        printf "Switching virtualenv: %s  " $1
60+     fi
61+
62      workon "$1"
63-     # For some reason python --version writes to stderr
64-     printf "[%s]\n" "$(python --version 2>&1)"
65+
66+     if [ -z "$AUTOSWITCH_SILENT" ]; then
67+       # For some reason python --version writes to stderr
68+       printf "[%s]\n" "$(python --version 2>&1)"
69+     fi
70   fi
71 }
72 
73@@ -18,8 +24,8 @@ function check_venv()
74         MYOLDPWD="$PWD"
75         if [[ -f ".venv" ]]; then
76            maybeworkon "$(cat .venv)"
77-        elif [[ -n "$DEFAULT_VIRTUALENV" ]]; then
78-           maybeworkon "$DEFAULT_VIRTUALENV"
79+        elif [[ -n "$AUTOSWITCH_DEFAULTENV" ]]; then
80+           maybeworkon "$AUTOSWITCH_DEFAULTENV"
81         elif [[ -n "$VIRTUAL_ENV" ]]; then
82            deactivate
83         fi