Bash: move ~/.bundle/bin to head of PATH
Bash: move ~/.bundle/bin to head of PATH

It would be nice if we could automatically use bundled executables when
working in a given project, but we can't add "./bundle/bin" to the head
of our PATH for the same reason that we can't add "." to our PATH
(security fail).

So, try the next best thing: add ~/.bundle/bin, combined with the
BUNDLE_PATH setting which was added previously.

Just say we call "rspec" from inside a project that has RSpec in its
Gemfile. This will effectively run the "rspec" stub that Bundler put in
~/.bundle/bin. This stub just requires RubyGems and tries to run
"bundler/setup" (ie. modifying the LOAD_PATH according to what's in the
Gemfile). The stub then looks for the "real" executable in the system
PATH and runs it; "real" because the executable at /usr/bin/rspec is
itself a stub, added by RubyGems. Because the environment has already
been set up by Bundler at this point, we end up running the desired
version of the gem.

If we run "rspec" from outside a project, where no Gemfile is present,
the "bundler/setup" call will do nothing, and when we pass control over
to the stub at /usr/bin/rspec execution will just follow the normal
RubyGems pattern of executing the latest available version.

This approach should be viable, even in the face of multiple projects
installing many different versions of gems into BUNDLE_PATH, because the
generated stubs should always be the same no matter what the
different version requirements specified in the different Gemfiles are.

Note that there is one open ticket in the Bundler tracker related to the
stubs that it creates:

  http://github.com/carlhuda/bundler/issues/441

Signed-off-by: Wincent Colaiuta <c76ac2e9cd86441713c7dfae92c451f3e6d17fdc@wincent.com>

wincent/wincent,wincent/wincent,wincent/wincent,wincent/wincent,wincent/wincent,wincent/wincent,wincent/wincent,wincent/wincent