module Acouchi class Which def self.find_executable *aliases if executable = aliases.find {|a| which? a} executable else raise %{Couldn't find any matches for the aliases "#{aliases.join(", ")}"} end end private def self.which? command ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exe = File.join(path, "#{command}") return exe if executable? exe end return nil end def self.executable? file return true if File.executable?(file) extensions = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [] File.exist?(file) && File.file?(file) && extensions.any? && extensions.any? {|e| file.downcase.end_with?(e.downcase)} end end end