Browse Source

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'
pull/360/head^2
Mislav Marohnić 10 years ago
parent
commit
8bac958994
2 changed files with 3 additions and 27 deletions
  1. +1
    -25
      libexec/rbenv-init
  2. +2
    -2
      test/init.bats

+ 1
- 25
libexec/rbenv-init View File

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

+ 2
- 2
test/init.bats View File

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

Loading…
Cancel
Save