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:
parent
9c8a73cf41
commit
d6299af86c
@ -152,12 +152,8 @@ def puts_columns items, star_items=[]
|
|||||||
end
|
end
|
||||||
|
|
||||||
def which cmd
|
def which cmd
|
||||||
path = `/usr/bin/which #{cmd} 2>/dev/null`.chomp
|
dir = ENV['PATH'].split(':').find {|p| File.executable? File.join(p, cmd)}
|
||||||
if path.empty?
|
Pathname.new(File.join(dir, cmd)) unless dir.nil?
|
||||||
nil
|
|
||||||
else
|
|
||||||
Pathname.new(path)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def which_editor
|
def which_editor
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user