Sha256: 4c1571b9b4d9ac1284831f72951e64e54445c0c3f76632751659e905ecbecfc5

Contents?: true

Size: 1.03 KB

Versions: 6500

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Byebug
  module Helpers
    #
    # Utilities for interaction with executables
    #
    module BinHelper
      #
      # Cross-platform way of finding an executable in the $PATH.
      # Adapted from: https://gist.github.com/steakknife/88b6c3837a5e90a08296
      #
      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

      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

      def search_paths
        ENV["PATH"].split(File::PATH_SEPARATOR)
      end

      def executable_file_extensions
        ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
      end

      def real_executable?(file)
        File.executable?(file) && !File.directory?(file)
      end
    end
  end
end

Version data entries

6,500 entries across 6,496 versions & 33 rubygems

Version Path
cybrid_api_organization_ruby-0.122.67 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_id_ruby-0.122.67 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_bank_ruby-0.122.66 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_organization_ruby-0.122.66 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_id_ruby-0.122.66 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_id_ruby-0.122.65 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_bank_ruby-0.122.65 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_organization_ruby-0.122.65 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_bank_ruby-0.122.64 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_id_ruby-0.122.64 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_organization_ruby-0.122.64 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_id_ruby-0.122.60 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_bank_ruby-0.122.60 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_organization_ruby-0.122.60 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_organization_ruby-0.122.59 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_bank_ruby-0.122.59 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_id_ruby-0.122.59 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_bank_ruby-0.122.58 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_organization_ruby-0.122.58 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb
cybrid_api_id_ruby-0.122.58 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/helpers/bin.rb