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'
This commit is contained in:
Mislav Marohnić 2014-01-04 16:37:20 +01:00
parent 5287e2ebf4
commit 8bac958994
2 changed files with 3 additions and 27 deletions

View file

@ -28,31 +28,7 @@ if [ -z "$shell" ]; then
shell="$(basename "${shell:-$SHELL}")" shell="$(basename "${shell:-$SHELL}")"
fi fi
READLINK=$(type -p greadlink readlink | head -1) root="${0%/*}/.."
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")/.."
if [ -z "$print" ]; then if [ -z "$print" ]; then
case "$shell" in case "$shell" in

View file

@ -21,7 +21,7 @@ load test_helper
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
run rbenv-init - bash run rbenv-init - bash
assert_success assert_success
assert_line "source '${root}/libexec/../completions/rbenv.bash'" assert_line "source '${root}/test/../libexec/../completions/rbenv.bash'"
} }
@test "detect parent shell" { @test "detect parent shell" {
@ -35,7 +35,7 @@ load test_helper
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
run rbenv-init - fish run rbenv-init - fish
assert_success assert_success
assert_line ". '${root}/libexec/../completions/rbenv.fish'" assert_line ". '${root}/test/../libexec/../completions/rbenv.fish'"
} }
@test "fish instructions" { @test "fish instructions" {