Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to pure-ruby which (actually windows-like where) #3

Closed
yaauie opened this issue Jul 5, 2013 · 0 comments
Closed

Switch to pure-ruby which (actually windows-like where) #3

yaauie opened this issue Jul 5, 2013 · 0 comments
Assignees

Comments

@yaauie
Copy link
Owner

yaauie commented Jul 5, 2013

This is a pre-requisite for #2. I may want to also be able to supply a PATH-like string manually instead of relying on ENV['PATH']

    # Analog of Windows `where` command, or a `which` that finds *all*
    # matching executables on the supplied path.
    # @param cmd [String] - the command to find
    # @return [Enumerable<String>] - the executables found, lazily.
    def find_executables(cmd)
      return enum_for(:find_executables, cmd) unless block_given?

      exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
      ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
        exts.each do |ext|
          exe = File.join(path, "#{cmd}#{ext}")
          yield exe if File.executable? exe
        end
      end
    end
@ghost ghost assigned yaauie Jul 5, 2013
@yaauie yaauie closed this as completed Jul 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant