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_cannot_install, pretty_deprecated, pretty_disabled, pretty_duration, pretty_install_status, pretty_installed, pretty_uninstalled, pretty_unmarked, pretty_upgradable, pretty_warning

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:



33
34
35
36
37
# File 'aliases/aliases.rb', line 33

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:



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

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 = meta.to_s[/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:



79
80
81
82
# File 'aliases/aliases.rb', line 79

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.



85
86
87
# File 'aliases/aliases.rb', line 85

def self.edit_all
  Utils::Editor.open(*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.



28
29
30
# File 'aliases/aliases.rb', line 28

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:



40
41
42
# File 'aliases/aliases.rb', line 40

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:



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

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:



70
71
72
73
74
75
76
# File 'aliases/aliases.rb', line 70

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