From 31fab8cdaebf4bb47d078a92154a09d0e0deccf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 28 Sep 2013 15:04:24 +0200 Subject: [PATCH] cleanup in fish Use process subtitution syntax: . (rbenv init -|psub) instead of: eval (rbenv init -) because the latter doesn't work well with newlines. --- libexec/rbenv-init | 17 +++++++++++------ libexec/rbenv-sh-rehash | 6 ++++-- test/init.bats | 6 +++--- test/rehash.bats | 14 ++++++++++++++ 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index c3a3bb02..c240460d 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -73,7 +73,14 @@ if [ -z "$print" ]; then { echo "# Load rbenv automatically by adding" echo "# the following to ${profile}:" echo - echo 'eval "$(rbenv init -)"' + case "$shell" in + fish ) + echo '. (rbenv init -|psub)' + ;; + * ) + echo 'eval "$(rbenv init -)"' + ;; + esac echo } >&2 @@ -85,7 +92,7 @@ mkdir -p "${RBENV_ROOT}/"{shims,versions} if [[ ":${PATH}:" != *:"${RBENV_ROOT}/shims":* ]]; then case "$shell" in fish ) - echo 'setenv PATH "'${RBENV_ROOT}'/shims"' '$PATH' ';' + echo "setenv PATH '${RBENV_ROOT}/shims' \$PATH" ;; * ) echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' @@ -94,7 +101,7 @@ if [[ ":${PATH}:" != *:"${RBENV_ROOT}/shims":* ]]; then fi completion="${root}/completions/rbenv.${shell}" -[ -r "$completion" ] && echo "source '$completion'" +[ -r "$completion" ] && echo ". '$completion'" if [ -z "$no_rehash" ]; then echo 'rbenv rehash 2>/dev/null' @@ -106,9 +113,7 @@ fish ) cat </dev/null || true" + or='||' ;; esac + +echo "hash -r 2>/dev/null $or true" diff --git a/test/init.bats b/test/init.bats index a4c63199..d0795eef 100644 --- a/test/init.bats +++ b/test/init.bats @@ -21,14 +21,14 @@ load test_helper root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" SHELL=/bin/bash run rbenv-init - assert_success - assert_line "source '${root}/libexec/../completions/rbenv.bash'" + assert_line ". '${root}/libexec/../completions/rbenv.bash'" } @test "setup shell completions (fish)" { root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" SHELL=/usr/bin/fish run rbenv-init - assert_success - assert_line '. "'${root}'/libexec/../completions/rbenv.fish";' + assert_line ". '${root}/libexec/../completions/rbenv.fish'" } @test "option to skip rehash" { @@ -48,7 +48,7 @@ load test_helper export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin" SHELL=/usr/bin/fish run rbenv-init - assert_success - assert_line 0 'setenv PATH "'${RBENV_ROOT}'/shims" $PATH ;' + assert_line 0 "setenv PATH '${RBENV_ROOT}/shims' \$PATH" } @test "doesn't add shims to PATH more than once" { diff --git a/test/rehash.bats b/test/rehash.bats index 97414410..97f6cd43 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -98,3 +98,17 @@ SH assert_success assert_output "HELLO=:hello:ugly:world:again" } + +@test "sh-rehash in bash" { + create_executable "2.0" "ruby" + SHELL=/bin/bash run rbenv-sh-rehash + assert_success "hash -r 2>/dev/null || true" + assert [ -x "${RBENV_ROOT}/shims/ruby" ] +} + +@test "sh-rehash in fish" { + create_executable "2.0" "ruby" + SHELL=/usr/bin/fish run rbenv-sh-rehash + assert_success "hash -r 2>/dev/null ; or true" + assert [ -x "${RBENV_ROOT}/shims/ruby" ] +}