Module: Utils::Shebang Private

Extended by:
T::Sig
Included in:
Formula
Defined in:
utils/shebang.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Helper functions for manipulating shebang lines.

Defined Under Namespace

Classes: RewriteInfo

Class Method Summary collapse

Class Method Details

.rewrite_shebang(rewrite_info, *paths) ⇒ void

This method returns an undefined value.

Rewrite shebang for the given paths using the given rewrite_info.

Examples:

rewrite_shebang detected_python_shebang, bin/"script.py"

Parameters:



36
37
38
39
40
41
42
43
44
# File 'utils/shebang.rb', line 36

def rewrite_shebang(rewrite_info, *paths)
  paths.each do |f|
    f = Pathname(f)
    next unless f.file?
    next unless rewrite_info.regex.match?(f.read(rewrite_info.max_length))

    Utils::Inreplace.inreplace f.to_s, rewrite_info.regex, "#!#{rewrite_info.replacement}"
  end
end