Module: Homebrew::Aliases Private

Extended by:
Utils::Output::Mixin
Defined in:
aliases/alias.rb,
aliases/aliases.rb

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.

Defined Under Namespace

Classes: Alias

Class Method Summary collapse

Methods included from Utils::Output::Mixin

issue_reporting_message, odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, opoo_without_github_actions_annotation, pretty_deprecated, pretty_disabled, pretty_duration, pretty_install_status, pretty_installed, pretty_outdated, pretty_uninstalled, pretty_upgradable

Class Method Details

.add(name, command) ⇒ void

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

This method returns an undefined value.

Parameters:



31
32
33
34
35
# File 'aliases/aliases.rb', line 31

def self.add(name, command)
  new_alias = Alias.new(name, command)
  odie "alias 'brew #{name}' already exists!" if new_alias.script.exist?
  new_alias.write
end

.each(only, &block) ⇒ void

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

This method returns an undefined value.

Parameters:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'aliases/aliases.rb', line 43

def self.each(only, &block)
  Dir["#{HOMEBREW_ALIASES}/*"].each do |path|
    next if path.end_with? "~" # skip Emacs-like backup files
    next if File.directory?(path)

    _shebang, meta, *lines = File.readlines(path)
    name = T.must(meta)[/alias: brew (\S+)/, 1] || File.basename(path)
    next if !only.empty? && only.exclude?(name)

    lines.reject! { |line| line.start_with?("#") || line =~ /^\s*$/ }
    first_line = lines.fetch(0)
    command = first_line.chomp
    command.sub!(/ \$\*$/, "")

    if command.start_with? "brew "
      command.sub!(/^brew /, "")
    else
      command = "!#{command}"
    end

    yield name, command if block.present?
  end
end

.edit(name, command = nil) ⇒ void

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

This method returns an undefined value.

Parameters:



77
78
79
80
# File 'aliases/aliases.rb', line 77

def self.edit(name, command = nil)
  Alias.new(name, command).write unless command.nil?
  Alias.new(name, command).edit
end

.edit_allvoid

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

This method returns an undefined value.



83
84
85
# File 'aliases/aliases.rb', line 83

def self.edit_all
  exec_editor(*Dir[HOMEBREW_ALIASES])
end

.initvoid

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

This method returns an undefined value.



26
27
28
# File 'aliases/aliases.rb', line 26

def self.init
  FileUtils.mkdir_p HOMEBREW_ALIASES
end

.remove(name) ⇒ void

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

This method returns an undefined value.

Parameters:



38
39
40
# File 'aliases/aliases.rb', line 38

def self.remove(name)
  Alias.new(name).remove
end

.reservedArray<String>

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

Lazily computed to avoid a load-time cycle: Commands.internal_commands requires every cmd/*.rb, including cmd/alias.rb, which itself requires this file.

Returns:



15
16
17
18
19
20
21
22
23
# File 'aliases/aliases.rb', line 15

def self.reserved
  @reserved ||= T.let(
    (Commands.internal_commands +
     Commands.internal_developer_commands +
     Commands.internal_commands_aliases +
     %w[alias unalias]).freeze,
    T.nilable(T::Array[String]),
  )
end

.show(*aliases) ⇒ void

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

This method returns an undefined value.

Parameters:



68
69
70
71
72
73
74
# File 'aliases/aliases.rb', line 68

def self.show(*aliases)
  each([*aliases]) do |name, command|
    puts "brew alias #{name}='#{command}'"
    existing_alias = Alias.new(name, command)
    existing_alias.link unless existing_alias.symlink.exist?
  end
end