Skip to content

Commit

Permalink
do not require PS1 to be bound
Browse files Browse the repository at this point in the history
  • Loading branch information
schang412 authored and asottile committed Sep 24, 2022
1 parent dd94d71 commit 54b5a75
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions rustenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 54b5a75

Please sign in to comment.