From e935cb12c1bde48b9e2005373fef96d8cfa76b2f Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Mon, 17 Dec 2012 09:33:20 -0600 Subject: 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 #16659. Signed-off-by: Misty De Meo --- Library/Homebrew/utils.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 0d1b63c8b..348dbbdea 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -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 -- cgit v1.2.3