Module: Homebrew::Aliases Private

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

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:



21
22
23
24
25
# File 'aliases/aliases.rb', line 21

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:



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

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)
    target = File.basename(path)
    next if !only.empty? && only.exclude?(target)

    lines.reject! { |line| line.start_with?("#") || line =~ /^\s*$/ }
    first_line = T.must(lines.first)
    cmd = first_line.chomp
    cmd.sub!(/ \$\*$/, "")

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

    yield target, cmd 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:



67
68
69
70
# File 'aliases/aliases.rb', line 67

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.



73
74
75
# File 'aliases/aliases.rb', line 73

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.



16
17
18
# File 'aliases/aliases.rb', line 16

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:



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

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:



58
59
60
61
62
63
64
# File 'aliases/aliases.rb', line 58

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