From 1411fa5a1624ca5eeb5582897373c58a715fe2d2 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 17 Aug 2011 17:35:23 -0500 Subject: [PATCH] Add experimental ruby-local-exec --- bin/ruby-local-exec | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 bin/ruby-local-exec diff --git a/bin/ruby-local-exec b/bin/ruby-local-exec new file mode 100755 index 00000000..af7d7e1a --- /dev/null +++ b/bin/ruby-local-exec @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# +# `ruby-local-exec` is a drop-in replacement for the standard Ruby +# shebang line: +# +# #!/usr/bin/env ruby-local-exec +# +# Use it for scripts inside a project with an `.rbenv-version` +# file. When you run the scripts, they'll use the project-specified +# Ruby version, regardless of what directory they're run from. Useful +# for e.g. running project tasks in cron scripts without needing to +# `cd` into the project first. + +set -e + +cwd="$(pwd)" +dirname="${1%/*}" + +cd "$dirname" +export RBENV_VERSION="$(rbenv version-name)" +cd "$cwd" + +exec ruby "$@"