utils: add which_all
Similar to which, except it returns all of paths where binary is found. i.e. it's equivalent to `which -a`.
This commit is contained in:
parent
f29699f77c
commit
66c0b06d72
@ -134,6 +134,10 @@ class Requirement
|
||||
super(cmd, ORIGINAL_PATHS.join(File::PATH_SEPARATOR))
|
||||
end
|
||||
|
||||
def which_all(cmd)
|
||||
super(cmd, ORIGINAL_PATHS.join(File::PATH_SEPARATOR))
|
||||
end
|
||||
|
||||
class << self
|
||||
include BuildEnvironmentDSL
|
||||
|
||||
|
||||
@ -361,6 +361,19 @@ def which(cmd, path = ENV["PATH"])
|
||||
nil
|
||||
end
|
||||
|
||||
def which_all(cmd, path = ENV["PATH"])
|
||||
path.split(File::PATH_SEPARATOR).map do |p|
|
||||
begin
|
||||
pcmd = File.expand_path(cmd, p)
|
||||
rescue ArgumentError
|
||||
# File.expand_path will raise an ArgumentError if the path is malformed.
|
||||
# See https://github.com/Homebrew/homebrew/issues/32789
|
||||
next
|
||||
end
|
||||
Pathname.new(pcmd) if File.file?(pcmd) && File.executable?(pcmd)
|
||||
end.compact.uniq
|
||||
end
|
||||
|
||||
def which_editor
|
||||
editor = ENV.values_at("HOMEBREW_EDITOR", "VISUAL", "EDITOR").compact.first
|
||||
return editor unless editor.nil?
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user