aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils.rb
diff options
context:
space:
mode:
authorMisty De Meo2012-12-17 09:33:20 -0600
committerMisty De Meo2012-12-27 19:37:21 -0400
commite935cb12c1bde48b9e2005373fef96d8cfa76b2f (patch)
tree68120c15a32fdad844d6b88fad8f11b091afd49c /Library/Homebrew/utils.rb
parent62b8c63f2b7305c070d1d8e4a80af29959ddbdf4 (diff)
downloadhomebrew-e935cb12c1bde48b9e2005373fef96d8cfa76b2f.tar.bz2
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 <mistydemeo@gmail.com>
Diffstat (limited to 'Library/Homebrew/utils.rb')
-rw-r--r--Library/Homebrew/utils.rb8
1 files changed, 2 insertions, 6 deletions
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