diff --git a/libexec/pyenv-init b/libexec/pyenv-init index a9f30c1b..757a443f 100755 --- a/libexec/pyenv-init +++ b/libexec/pyenv-init @@ -322,12 +322,12 @@ function pyenv { } if ( ("${commands[*]}" -split ' ') -contains \$command ) { - \$shell_cmds = &pyenv sh-\$command \$args + \$shell_cmds = (& (get-command -commandtype application pyenv) sh-\$command \$args) if ( \$shell_cmds.Count -gt 0 ) { iex (\$shell_cmds -join "\`n") } } else { - & \$Env:PYENV_ROOT/bin/pyenv \$command \$args + & (get-command -commandtype application pyenv) \$command \$args } } EOS diff --git a/libexec/pyenv-sh-rehash b/libexec/pyenv-sh-rehash index 0e4f664c..afa5c799 100755 --- a/libexec/pyenv-sh-rehash +++ b/libexec/pyenv-sh-rehash @@ -13,7 +13,7 @@ shell="$(basename "${PYENV_SHELL:-$SHELL}")" # then tell the shell to empty its command lookup cache. case "$shell" in pwsh) - echo "&pyenv rehash" + echo "& (get-command pyenv -commandtype application) rehash" ;; *) echo "command pyenv rehash" @@ -21,7 +21,7 @@ esac case "$shell" in fish | pwsh ) - # no rehash support + # no executable cache ;; * ) echo "hash -r 2>/dev/null || true" diff --git a/test/rehash.bats b/test/rehash.bats index 7a420d9c..c878a3da 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -131,14 +131,20 @@ hash -r 2>/dev/null || true" @test "sh-rehash in pwsh" { create_alt_executable_in_version "3.4" "python" PYENV_SHELL=pwsh run pyenv-sh-rehash - assert_success "&pyenv rehash" + assert_success "& (get-command pyenv -commandtype application) rehash" } @test "sh-rehash in pwsh (integration)" { command -v pwsh >/dev/null || skip "-- pwsh not installed" + assert [ ! -x "${PYENV_ROOT}/shims/python" ] create_alt_executable_in_version "3.4" "python" - PYENV_SHELL=pwsh run pwsh -nop -c 'iex ((&pyenv-sh-rehash) -join "\`n")' - assert_success + run pwsh -nop -c -<<'!' +$ErrorActionPreference = "Stop" +$PSNativeCommandUseErrorActionPreference = $true +iex ((& pyenv init - pwsh) -join "`n") +& pyenv rehash +! + assert_success "" assert [ -x "${PYENV_ROOT}/shims/python" ] }