From f897c502022cf3132574afc084fddf9252644d72 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Sun, 25 Dec 2022 07:35:03 +0800 Subject: [PATCH] Fix non-bash output while detecting shell (#2561) Co-authored-by: Ivan Pozdeev --- libexec/pyenv-init | 13 ++++++++++--- test/init.bats | 6 ++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libexec/pyenv-init b/libexec/pyenv-init index 3d21f31f..8bc8bc36 100755 --- a/libexec/pyenv-init +++ b/libexec/pyenv-init @@ -83,7 +83,7 @@ function main() { exit 0 ;; "detect-shell") - detect_profile + detect_profile 1 print_detect_shell exit 0 ;; @@ -93,6 +93,8 @@ function main() { } function detect_profile() { + local detect_for_detect_shell="$1" + case "$shell" in bash ) if [ -e '~/.bash_profile' ]; then @@ -112,8 +114,13 @@ function detect_profile() { rc='~/.profile' ;; * ) - profile='your shell'\''s login startup file' - rc='your shell'\''s interactive startup file' + if [ -n "$detect_for_detect_shell" ]; then + profile= + rc= + else + profile='your shell'\''s login startup file' + rc='your shell'\''s interactive startup file' + fi ;; esac } diff --git a/test/init.bats b/test/init.bats index bfe253e3..21109c94 100755 --- a/test/init.bats +++ b/test/init.bats @@ -63,6 +63,12 @@ OUT assert_line 'pyenv init - | source' } +@test "shell detection for installer" { + run pyenv-init --detect-shell + assert_success + assert_line "PYENV_SHELL_DETECT=bash" +} + @test "option to skip rehash" { run pyenv-init - --no-rehash assert_success