From be5e1a4ded1d0634bb73de6d4ba424da390c7837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 6 Dec 2013 16:45:22 +0100 Subject: [PATCH] Improve `rbenv init` instructions for fish Fish user config file `~/.config/fish/config.fish` loads for every instance of fish shell, not just interactive ones. Since it's unnecessary and dangerous to eval `rbenv init -` output in non-interactive shells, wrap the invocation in a conditional that checks if the current shell is interactive. Fixes #501 --- libexec/rbenv-init | 2 +- test/init.bats | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index dcb1bd5a..a3292d66 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -77,7 +77,7 @@ if [ -z "$print" ]; then echo case "$shell" in fish ) - echo '. (rbenv init -|psub)' + echo 'status --is-interactive; and . (rbenv init -|psub)' ;; * ) echo 'eval "$(rbenv init -)"' diff --git a/test/init.bats b/test/init.bats index 54086e5f..61b30be7 100644 --- a/test/init.bats +++ b/test/init.bats @@ -38,6 +38,12 @@ load test_helper assert_line ". '${root}/libexec/../completions/rbenv.fish'" } +@test "fish instructions" { + run rbenv-init fish + assert [ "$status" -eq 1 ] + assert_line 'status --is-interactive; and . (rbenv init -|psub)' +} + @test "option to skip rehash" { run rbenv-init - --no-rehash assert_success