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

Constant Summary collapse

RESERVED =

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

T.let((
  Commands.internal_commands +
  Commands.internal_developer_commands +
  Commands.internal_commands_aliases +
  %w[alias unalias]
).freeze, T::Array[String])

Class Method Summary collapse

Methods included from Utils::Output::Mixin

odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, pretty_duration, pretty_installed, pretty_outdated, pretty_uninstalled

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:



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

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:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'aliases/aliases.rb', line 36

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:



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

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.



76
77
78
# File 'aliases/aliases.rb', line 76

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.



19
20
21
# File 'aliases/aliases.rb', line 19

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:



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

def self.remove(name)
  Alias.new(name).remove
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:



61
62
63
64
65
66
67
# File 'aliases/aliases.rb', line 61

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