cleanup in fish

Use process subtitution syntax:

    . (rbenv init -|psub)

instead of:

    eval (rbenv init -)

because the latter doesn't work well with newlines.
This commit is contained in:
Mislav Marohnić 2013-09-28 15:04:24 +02:00
parent 5bfec84432
commit 31fab8cdae
4 changed files with 32 additions and 11 deletions

View file

@ -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 <<EOS
function rbenv
set command \$argv[1]
if [ (count \$argv) -gt 0 ]
set -e argv[1]
end
set -e argv[1]
switch "\$command"
case ${commands[*]}

View file

@ -15,9 +15,11 @@ rbenv-rehash
case "$shell" in
fish )
# nothing to do
or='; or'
;;
* )
echo "hash -r 2>/dev/null || true"
or='||'
;;
esac
echo "hash -r 2>/dev/null $or true"

View file

@ -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" {

View file

@ -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" ]
}