From d061cb46515d7854f001ab07743ac69ab1e8edd4 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 13 Jul 2018 22:22:17 +0200 Subject: [PATCH] Have `rbenv init` print instructions that hardcode the detected shell This speeds up subsequent `rbenv init -` executions for the user who followed these instructions because the shell will no longer have to be detected each time. --- libexec/rbenv-init | 4 ++-- test/init.bats | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index acc9e40..ae2da55 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -71,10 +71,10 @@ if [ -z "$print" ]; then echo case "$shell" in fish ) - echo 'status --is-interactive; and rbenv init - | source' + echo 'status --is-interactive; and rbenv init - fish | source' ;; * ) - echo 'eval "$(rbenv init -)"' + printf 'eval "$(rbenv init - %s)"\n' "$shell" ;; esac echo diff --git a/test/init.bats b/test/init.bats index d3548f0..63fc8c6 100755 --- a/test/init.bats +++ b/test/init.bats @@ -51,10 +51,16 @@ OUT [ -z "$line" ] || flunk "did not expect line: $line" } +@test "posix shell instructions" { + run rbenv-init bash + assert [ "$status" -eq 1 ] + assert_line 'eval "$(rbenv init - bash)"' +} + @test "fish instructions" { run rbenv-init fish assert [ "$status" -eq 1 ] - assert_line 'status --is-interactive; and rbenv init - | source' + assert_line 'status --is-interactive; and rbenv init - fish | source' } @test "option to skip rehash" {