Skip to content

Commit

Permalink
Speed up rbenv-rehash by using hard links
Browse files Browse the repository at this point in the history
  • Loading branch information
sstephenson committed Aug 4, 2011
1 parent 7ce04a6 commit fffb29d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions libexec/rbenv-rehash
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
#!/usr/bin/env bash -e

create_prototype_shim() {
cat > .rbenv-shim <<SH
#!/usr/bin/env bash -e
exec rbenv exec "\${0##*/}" "\$@"
SH
chmod +x .rbenv-shim
}

make_shims() {
local glob="$@"

for file in $glob; do
local shim="${file##*/}"
cat > "$shim" <<SH
#!/bin/sh
exec rbenv exec $shim "\$@"
SH
chmod +x "$shim"
[ -e "$shim" ] || ln -f .rbenv-shim "$shim"
done
}

mkdir -p "${HOME}/.rbenv/shims"
cd "${HOME}/.rbenv/shims"
rm -f *

create_prototype_shim
make_shims ../versions/*/bin/*

shopt -s nullglob
Expand All @@ -26,3 +31,5 @@ shopt -u nullglob
for script in ${RBENV_REHASH_PLUGINS[@]}; do
source $script
done

rm -f .rbenv-shim

1 comment on commit fffb29d

@sstephenson
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before:

$ time rbenv rehash

real    0m0.416s
user    0m0.111s
sys 0m0.270s

After:

$ time rbenv rehash

real    0m0.135s
user    0m0.039s
sys 0m0.080s

Please sign in to comment.