4e9685d8f5a368b580efe6bd3554c89636476b04

Author
Jongwook Choi <wookayin@gmail.com>
Committer
Jongwook Choi <wookayin@gmail.com>
Date

Message

Handle properly a case where VIRTUAL_ENV is unset

If `$VIRTUAL_ENV` is not set but `.venv` exists (when auto-switching
occurs), the following happens:

```
basename: missing operand
Try 'basename --help' for more information.
Switching virtualenv: xxxxx  [Python 2.7.12]
```

To avoid this, we add a condition to check whether VIRTUAL_ENV is set.

Diff

 1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
 2index bb80f3c4502cb8786e0234ea66ec0dbc29bba01e..effa6d695163b61af167bdaaa19dfe8b45cd9108 100644
 3--- a/autoswitch_virtualenv.plugin.zsh
 4+++ b/autoswitch_virtualenv.plugin.zsh
 5@@ -3,7 +3,7 @@ function precmd() {
 6 }
 7 
 8 function maybeworkon() {
 9-  if [ "$1" != "$(basename $VIRTUAL_ENV)" ]; then
10+  if [[ -z "$VIRTUAL_ENV" || "$1" != "$(basename $VIRTUAL_ENV)" ]]; then
11      if [ -z "$AUTOSWITCH_SILENT" ]; then
12         printf "Switching virtualenv: %s  " $1
13      fi