utils: replace shell which with native code

Originally written for tigerbrew, but useful enough for core.
Replaces the shelled-out which in utils.rb with a native-ruby
equivalent, which is moderately faster.

Closes Homebrew/homebrew#16659.

Signed-off-by: Misty De Meo <mistydemeo@gmail.com>
This commit is contained in:
Misty De Meo 2012-12-17 09:33:20 -06:00
parent 9c8a73cf41
commit d6299af86c

View File

@ -152,12 +152,8 @@ def puts_columns items, star_items=[]
end
def which cmd
path = `/usr/bin/which #{cmd} 2>/dev/null`.chomp
if path.empty?
nil
else
Pathname.new(path)
end
dir = ENV['PATH'].split(':').find {|p| File.executable? File.join(p, cmd)}
Pathname.new(File.join(dir, cmd)) unless dir.nil?
end
def which_editor