Merge pull request #243 from JeanMertz/patch-1

Rewrite `bundle exec` wrapper to be more robust
This commit is contained in:
Bruno 2014-11-02 11:20:50 -02:00
commit 8a5acc8ce9

View File

@ -1,32 +1,54 @@
# The following is based on https://github.com/gma/bundler-exec # These methods override the default calls to append `bundle exec` if this gem
# is available within the context of bundler.
#
set -l execs annotate \
cap \
capify \
cucumber \
dashing \
foreman \
guard \
kitchen \
middleman \
nanoc \
puma \
rackup \
rainbows \
rake \
rspec \
rubocop \
ruby \
shotgun \
sidekiq \
spec \
spinach \
spork \
thin \
thor \
unicorn \
unicorn_rails
## Functions set -l do_eval (function --help | grep -q 'inheritvariable'; and echo false)
function _bundler-installed
which bundle >/dev/null ^&1
end
function _within-bundled-project for executable in $execs
set -l check_dir $PWD if test -z "$do_eval"
while [ $check_dir != "/" ] eval "function $executable; __execute_as_bundler $executable \$argv; end"
test -f "$check_dir/Gemfile"; and return else
set check_dir (dirname $check_dir) function $executable --inherit-variable executable
__execute_as_bundler $executable $argv
end
end end
false
end end
function _run-with-bundler function __execute_as_bundler
if begin; _bundler-installed; and _within-bundled-project; end if __is_a_bundled_executable $argv[1]
command bundle exec $argv command bundle exec $argv
else else
eval command $argv eval command $argv
end end
end end
### Main program function __is_a_bundled_executable
set -l bundled_commands annotate cap capify cucumber dashing foreman guard middleman nanoc puma rackup rainbows rake rspec ruby shotgun sidekiq spec spinach spork thin thor unicorn unicorn_rails set -l bindir (command bundle exec ruby -e 'puts Gem.bindir')
test -f "$bindir/$argv"
for cmd in $bundled_commands
if not contains $cmd bundle gem
eval "function $cmd; _run-with-bundler $cmd \$argv;end"
end
end end