From 8bac95899491cc043a40b274be224236a8224483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 4 Jan 2014 16:37:20 +0100 Subject: [PATCH] Stop using `abs_dirname()` in rbenv-init It's slow and not necessary since we expect `$0` to already be expanded. In tests this change forces us to deal with some relative paths, but it's not a big deal. The `rbenv init -` output in the most common case will be the same as before: source '/home/myuser/.rbenv/libexec/../completions/rbenv.bash' --- libexec/rbenv-init | 26 +------------------------- test/init.bats | 4 ++-- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 5f9079a7..8718c116 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -28,31 +28,7 @@ if [ -z "$shell" ]; then shell="$(basename "${shell:-$SHELL}")" fi -READLINK=$(type -p greadlink readlink | head -1) -if [ -z "$READLINK" ]; then - echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2 - exit 1 -fi - -resolve_link() { - $READLINK "$1" -} - -abs_dirname() { - local cwd="$(pwd)" - local path="$1" - - while [ -n "$path" ]; do - cd "${path%/*}" - local name="${path##*/}" - path="$(resolve_link "$name" || true)" - done - - pwd - cd "$cwd" -} - -root="$(abs_dirname "$0")/.." +root="${0%/*}/.." if [ -z "$print" ]; then case "$shell" in diff --git a/test/init.bats b/test/init.bats index aa50f091..2587a014 100644 --- a/test/init.bats +++ b/test/init.bats @@ -21,7 +21,7 @@ load test_helper root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" run rbenv-init - bash assert_success - assert_line "source '${root}/libexec/../completions/rbenv.bash'" + assert_line "source '${root}/test/../libexec/../completions/rbenv.bash'" } @test "detect parent shell" { @@ -35,7 +35,7 @@ load test_helper root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" run rbenv-init - fish assert_success - assert_line ". '${root}/libexec/../completions/rbenv.fish'" + assert_line ". '${root}/test/../libexec/../completions/rbenv.fish'" } @test "fish instructions" {