diff options
author | Erik Michaels-Ober <sferik@gmail.com> | 2011-12-02 19:19:56 -0800 |
---|---|---|
committer | Erik Michaels-Ober <sferik@gmail.com> | 2011-12-02 19:19:56 -0800 |
commit | 36c9f92a9fa4ff8f8700d27d426c553c37be361f (patch) | |
tree | 981bcbd9ad3aaa73ca9bb70aaaf4a2af2a4ea684 | |
parent | d1bed41cabf3dbba3a4835fbf38ee937d048783a (diff) | |
parent | d3a69d32af97bf7c9d04eb2d258d152f102e9910 (diff) | |
download | bundler-36c9f92a9fa4ff8f8700d27d426c553c37be361f.tar.gz |
Merge pull request #1573 from tenderlove/shell
Search $PATH for a binary rather than shelling out to `which`
-rw-r--r-- | lib/bundler.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 97e6e28300..53b5125101 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -229,7 +229,7 @@ module Bundler path = bundle_path path = path.parent until path.exist? - sudo_present = !(`which sudo` rescue '').empty? + sudo_present = which "sudo" bin_dir = Pathname.new(Bundler.system_bindir) bin_dir = bin_dir.parent until bin_dir.exist? @@ -246,6 +246,17 @@ module Bundler end end + def which(binary) + if File.executable? binary + binary + else + path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |path| + File.executable? File.join(path, binary) + } + path && File.expand_path(binary, path) + end + end + def sudo(str) `sudo -p 'Enter your password to install the bundled RubyGems to your system: ' #{str}` end |