8bb8969ca015f61d8413fbd69a5618c643eb09f0

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

Message

Fail and ouptut error message if mkvenv is run with an existing .venv
file

Diff

 1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
 2index ce021d90830923919a740e8966d0df2318b87964..ada04a71f696eb82fc6920bea7f598817177dc79 100644
 3--- a/autoswitch_virtualenv.plugin.zsh
 4+++ b/autoswitch_virtualenv.plugin.zsh
 5@@ -61,14 +61,18 @@ function rmvenv()
 6 # helper function to create a virtual environment for the current directory
 7 function mkvenv()
 8 {
 9-   venv_name="$(basename $PWD)"
10-   echo "$venv_name" > ".venv"
11-   mkvirtualenv "$venv_name" $@
12-   if [[ -f "requirements.txt" ]]; then
13-    printf "Found a requirements.txt. Install? (Y/n): "
14-    read install_prompt
15-    if [[ "$install_prompt" != "n" ]]; then
16-      pip install -r requirements.txt
17+  if [[ -f ".venv" ]]; then
18+    echo ".venv file already exists. If this is a mistake use the rmvenv command"
19+  else
20+    venv_name="$(basename $PWD)"
21+    echo "$venv_name" > ".venv"
22+    mkvirtualenv "$venv_name" $@
23+    if [[ -f "requirements.txt" ]]; then
24+      printf "Found a requirements.txt. Install? (Y/n): "
25+      read install_prompt
26+      if [[ "$install_prompt" != "n" ]]; then
27+        pip install -r requirements.txt
28+      fi
29     fi
30   fi
31 }