Method: Howzit::Util.command_exist?
- Defined in:
- lib/howzit/util.rb
.command_exist?(command) ⇒ Boolean
Test if external command exists
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/howzit/util.rb', line 40 def command_exist?(command) exts = ENV.fetch('PATHEXT', '').split(::File::PATH_SEPARATOR) command = File.(command) if command =~ /^~/ 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 |