From d6299af86c6f8304f629184298114ef244e52bd8 Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Mon, 17 Dec 2012 09:33:20 -0600 Subject: [PATCH] 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 --- Library/Homebrew/utils.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 0d1b63c8be..348dbbdea2 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