Module: Utils::Shebang Private

Includes:
Kernel
Included in:
Formula
Defined in:
utils/shebang.rb,
utils/shebang.rbi

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

Methods included from Kernel

#disk_usage_readable, #ensure_executable!, #ensure_formula_installed!, #exec_browser, #exec_editor, #ignore_interrupts, #interactive_shell, #number_readable, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #paths, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled, #quiet_system, #redact_secrets, #redirect_stdout, #require?, #safe_system, #tap_and_name_comparison, #truncate_text_to_approximate_size, #which, #which_all, #which_editor, #with_custom_locale, #with_env, #with_homebrew_path

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:



31
32
33
34
35
36
37
38
39
# File 'utils/shebang.rb', line 31

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