diff --git a/libexec/pyenv-sh-rehash b/libexec/pyenv-sh-rehash index b0dab063..0e4f664c 100755 --- a/libexec/pyenv-sh-rehash +++ b/libexec/pyenv-sh-rehash @@ -11,7 +11,13 @@ shell="$(basename "${PYENV_SHELL:-$SHELL}")" # When pyenv shell integration is enabled, delegate to pyenv-rehash, # then tell the shell to empty its command lookup cache. -echo "command pyenv rehash" +case "$shell" in +pwsh) + echo "&pyenv rehash" + ;; +*) + echo "command pyenv rehash" +esac case "$shell" in fish | pwsh ) diff --git a/test/rehash.bats b/test/rehash.bats index 34e18d7c..7d5fe35f 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -128,10 +128,17 @@ hash -r 2>/dev/null || true" assert [ -x "${PYENV_ROOT}/shims/python" ] } -@test "sh-rehash in pwsh" { +@test "sh-rehash in powershell" { create_executable "3.4" "python" PYENV_SHELL=pwsh run pyenv-sh-rehash - assert_success "" + assert_success "&pyenv rehash" +} + +@test "sh-rehash in powershell (integration)" { + command -v pwsh >/dev/null || skip "-- powershell not installed" + create_alt_executable_in_version "3.4" "python" + run pwsh -NoProfile -Command "iex (&pyenv-sh-rehash)" + assert_success assert [ -x "${PYENV_ROOT}/shims/python" ] }