Method: TTY::Pager::SystemPager.command_exist?
- Defined in:
- lib/tty/pager/system.rb
.command_exist?(command) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if command exists
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tty/pager/system.rb', line 26 def self.command_exist?(command) exts = ENV.fetch("PATHEXT", "").split(::File::PATH_SEPARATOR) if Pathname.new(command).absolute? ::File.exist?(command) || exts.any? { |ext| ::File.exist?("#{command}#{ext}")} else ENV.fetch("PATH", "").split(::File::PATH_SEPARATOR).any? do |dir| file = ::File.join(dir, command) ::File.exist?(file) || exts.any? { |ext| ::File.exist?("#{file}#{ext}") } end end end |