module Byebug::Helpers::BinHelper

Utilities for interaction with executables

Public Instance Methods

executable_file_extensions() click to toggle source
# File lib/byebug/helpers/bin.rb, line 37
def executable_file_extensions
  ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
end
find_executable(path, cmd) click to toggle source
# File lib/byebug/helpers/bin.rb, line 23
def find_executable(path, cmd)
  executable_file_extensions.each do |ext|
    exe = File.expand_path(cmd + ext, path)

    return exe if real_executable?(exe)
  end

  nil
end
real_executable?(file) click to toggle source
# File lib/byebug/helpers/bin.rb, line 41
def real_executable?(file)
  File.executable?(file) && !File.directory?(file)
end
search_paths() click to toggle source
# File lib/byebug/helpers/bin.rb, line 33
def search_paths
  ENV["PATH"].split(File::PATH_SEPARATOR)
end
which(cmd) click to toggle source

Cross-platform way of finding an executable in the $PATH. Adapted from: gist.github.com/steakknife/88b6c3837a5e90a08296

# File lib/byebug/helpers/bin.rb, line 12
def which(cmd)
  return File.expand_path(cmd) if File.exist?(cmd)

  [nil, *search_paths].each do |path|
    exe = find_executable(path, cmd)
    return exe if exe
  end

  nil
end