rbenv requires you to manually run "bundle exec" if you're running an executable from a gem, to avoid loading a different version of that gem compared with your Gemfile.
Are there any downsides to having the rbenv shims run "bundle exec" when a Gemfile is present in the current directory? It's a somewhat naive approach, because it doesn't handle Gemfile's that are further up the directory tree, but I don't need that behavior. The change would also make sure the current shim isn't named "bundle" or there could be an infinite recursion.
Patch:
diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash
index eebc4d3..00f4ec0 100755
--- a/libexec/rbenv-rehash
+++ b/libexec/rbenv-rehash
@@ -38,7 +38,14 @@ create_prototype_shim() {
#!/usr/bin/env bash
set -e
export RBENV_ROOT="$RBENV_ROOT"
-exec rbenv exec "\${0##*/}" "\$@"
+# This only handles Gemfile in current dir
+if [[ \$RBENV_AUTO_BUNDLE = '1' && -e Gemfile && \`basename \$0\` != 'bundle' ]]; then
+ exec 3>/dev/tty
+ echo "rbenv: Using Gemfile" >&3
+ exec rbenv exec bundle exec "\${0##*/}" "\$@"
+else
+ exec rbenv exec "\${0##*/}" "\$@"
+fi
SH
chmod +x "$PROTOTYPE_SHIM_PATH"
}
You must set environment variable RBENV_AUTO_BUNDLE=1 to enable the auto "bundle exec" behavior.
If there's enough demand I might submit a patch.
To apply the patch, just put the patch file in your .rbenv dir, and run
git apply PATCHFILE
To test the patch, you'll have to delete your shims and run "rbenv rehash".
To undo:
git apply -R PATCHFILE
or
git checkout -- libexec/rbenv-rehash
then recreate the shims again.
It does seem that vim will run some ruby when you load a ruby file, and bundle exec will be used with that too. You could disable the auto behavior via let $RBENV_AUTO_BUNDLE=0
.
rbenv requires you to manually run "bundle exec" if you're running an executable from a gem, to avoid loading a different version of that gem compared with your Gemfile.
Unless you use the rbenv-bundler plugin, which IMHO is a saner approach than trying to reimplemented that behavior yourself. If there's anything missing from that plugin, rather contribute it there.