diff --git a/libexec/pyenv-init b/libexec/pyenv-init index c1e0da7b..98b8c48e 100755 --- a/libexec/pyenv-init +++ b/libexec/pyenv-init @@ -15,6 +15,7 @@ if [ "$1" = "--complete" ]; then echo bash echo fish echo ksh + echo pwsh echo zsh exit fi @@ -105,6 +106,10 @@ function detect_profile() { profile_explain="~/.bash_profile if it exists, otherwise ~/.profile" rc='~/.bashrc' ;; + pwsh ) + profile='~/.config/powershell/profile.ps1' + rc='~/.config/powershell/profile.ps1' + ;; zsh ) profile='~/.zprofile' rc='~/.zshrc' @@ -153,6 +158,21 @@ function help_() { echo 'pyenv init - | source' echo ;; + pwsh ) + echo '# Load pyenv automatically by appending' + echo -n "# the following to " + if [ "$profile" == "$rc" ]; then + echo "$profile :" + else + echo + echo "${profile_explain:-$profile} (for login shells)" + echo "and $rc (for interactive shells) :" + fi + echo + echo '$Env:PYENV_ROOT="$HOME/.pyenv"' + echo '$Env:PATH="$Env:PYENV_ROOT/bin:$Env:PATH"' + echo 'iex ((pyenv init -) -join "`n")' + ;; * ) echo '# Load pyenv automatically by appending' echo -n "# the following to " @@ -189,6 +209,11 @@ function print_path() { print_path_prepend_shims echo 'end' ;; + pwsh ) + echo 'if ( $Env:PATH -match "'"${PYENV_ROOT}/shims"'" ) {' + print_path_prepend_shims + echo '}' + ;; * ) echo 'if [[ ":$PATH:" != *'\':"${PYENV_ROOT}"/shims:\''* ]]; then' print_path_prepend_shims @@ -202,6 +227,10 @@ function print_path() { echo 'set -eg PATH[$pyenv_index]; end; set -e pyenv_index' print_path_prepend_shims ;; + pwsh ) + echo '$Env:PATH="$(($Env:PATH -split '"':'"' | where { -not ($_ -match '"'${PYENV_ROOT}/shims'"') }) -join '"':'"')"' + print_path_prepend_shims + ;; * ) # Some distros (notably Debian-based) set Bash's SSH_SOURCE_BASHRC compilation option # that makes it source `bashrc` under SSH even when not interactive. @@ -226,6 +255,9 @@ function print_path_prepend_shims() { fish ) echo 'set -gx PATH '\'"${PYENV_ROOT}/shims"\'' $PATH' ;; + pwsh ) + echo '$Env:PATH="'"${PYENV_ROOT}"'/shims:$Env:PATH"' + ;; * ) echo 'export PATH="'"${PYENV_ROOT}"'/shims:${PATH}"' ;; @@ -237,6 +269,9 @@ function print_env() { fish ) echo "set -gx PYENV_SHELL $shell" ;; + pwsh ) + echo '$Env:PYENV_SHELL="'"$shell"'"' + ;; * ) echo "export PYENV_SHELL=$shell" ;; @@ -252,7 +287,14 @@ function print_completion() { function print_rehash() { if [ -z "$no_rehash" ]; then + case "$shell" in + pwsh ) + echo '& pyenv rehash 2>/dev/null' + ;; + * ) echo 'command pyenv rehash 2>/dev/null' + ;; + esac fi } @@ -272,6 +314,25 @@ function pyenv command pyenv "\$command" \$argv end end +EOS + ;; + pwsh ) + cat <&2 false end +EOS + ;; + pwsh ) + cat </dev/null; then echo 'set -gu PYENV_VERSION_OLD "$PYENV_VERSION"' echo "set -gx PYENV_VERSION \"$version\"" ;; + pwsh ) + echo '$Env:PYENV_VERSION, $Env:PYENV_VERSION_OLD = "'"${version}"'", $Env:PYENV_VERSION' + ;; * ) echo 'PYENV_VERSION_OLD="${PYENV_VERSION-}"' echo "export PYENV_VERSION=\"${version}\""