aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMisty De Meo2012-12-17 09:33:20 -0600
committerMisty De Meo2012-12-27 19:37:21 -0400
commitd6299af86c6f8304f629184298114ef244e52bd8 (patch)
tree4fbc7b165c002ddb57c87702c1e494bc72e6ad76 /Library
parent9c8a73cf417a009e0bfa957ae942193febae14bf (diff)
downloadbrew-d6299af86c6f8304f629184298114ef244e52bd8.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 Homebrew/homebrew#16659. Signed-off-by: Misty De Meo <mistydemeo@gmail.com>
Diffstat (limited to 'Library')
-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