Module: Utils::Shebang Private

Extended by:
T::Helpers
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.

Example

rewrite_shebang detected_python_shebang, bin/"script.py"

Parameters:



42
43
44
45
46
47
48
49
50
# File 'utils/shebang.rb', line 42

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