Repository: chriskuehl/rustenv (language: python)

Issue:
activate script doesn't work if there's no PS1 and the shell is `set -e`
This happens e.g. in bash scripts (as opposed to logged-in sessions).

```
$ cat test.sh
#!/bin/bash
set -euo pipefail
. renv/bin/activate

$ ./test.sh  
renv/bin/activate: line 6: PS1: unbound variable
```

It should probably skip setting the PS1 in this case entirely?


Discussion / hints:
Hi,

Thanks for writing this software. Is it okay if I take a look at fixing this issue? While fixing this, I would also like to add a feature to read `VIRTUAL_ENV_DISABLE_PROMPT` (the same variable that is read in Python venv activation script) to determine if we should set the PS1 variable. 

Thanks. 
those seem unrelated -- and I don't think rustenv should read virtualenv's environment variables -- but feel free to work on fixing this bug at least

Fix patch:
diff --git a/rustenv.py b/rustenv.py
index 4cdbbc2..f2b8aff 100644
--- a/rustenv.py
+++ b/rustenv.py
@@ -31,15 +31,17 @@
 
 # TODO: it might be nice to intelligently add/remove from PATH/PS1 instead of
 # just restoring the old one
-_RUSTENV_OLD_PS1="$PS1"
+_RUSTENV_OLD_PS1="${{PS1-}}"
 _RUSTENV_OLD_PATH="$PATH"
 
 export PATH="$_RUSTENV_BIN_PATH:$PATH"
-export PS1="($_RUSTENV_NAME) $PS1"
+export PS1="($_RUSTENV_NAME) ${{PS1-}}"
 hash -r 2>/dev/null
 
 deactivate_rustenv() {{
-    export PS1="$_RUSTENV_OLD_PS1"
+    if ! [ -z "${{_RUSTENV_OLD_PS1+_}}" ] ; then
+        export PS1="$_RUSTENV_OLD_PS1"
+    fi
     export PATH="$_RUSTENV_OLD_PATH"
     hash -r 2>/dev/null
 


Test patch:
diff --git a/tests/integration_test.py b/tests/integration_test.py
index e1b3e5c..073695d 100644
--- a/tests/integration_test.py
+++ b/tests/integration_test.py
@@ -102,3 +102,16 @@ def test_runenv_shell(shell, not_found_message, built_rustenv, tmpdir):
 
     assert stages['installed']['hello'] == 'Hello World!'
     assert stages['uninstalled'] == stages['activated']
+
+
+@pytest.mark.parametrize('shell', ('bash', 'zsh'))
+def test_works_without_ps1(shell, built_rustenv, tmpdir):
+    test_script = tmpdir.join('test.sh')
+    test_script.write(
+        """
+        unset PS1
+        set -euo pipefail
+        . {}/bin/activate
+        """.format(built_rustenv.strpath),
+    )
+    subprocess.check_output((shell, test_script.strpath))