diff --git a/rustenv.py b/rustenv.py
index 4cdbbc2..f2b8aff 100644
--- a/rustenv.py
+++ b/rustenv.py
@@ -31,15 +31,17 @@ _RUSTENV_NAME='{RUSTENV_NAME}'
 
 # 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
 

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))

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?
tests/integration_test.py::test_works_without_ps1[bash]
tests/integration_test.py::test_runenv_shell[bash-{}: tests/integration_test.py::test_rustenv_looks_sane