mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Merge pull request #20246 from Homebrew/alias-symlink-names
aliases/aliases: fix naming of symlinks
This commit is contained in:
commit
b631179579
@ -29,36 +29,36 @@ module Homebrew
|
|||||||
Alias.new(name).remove
|
Alias.new(name).remove
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(only: T::Array[String], block: T.proc.params(target: String, cmd: String).void).void }
|
sig { params(only: T::Array[String], block: T.proc.params(name: String, command: String).void).void }
|
||||||
def self.each(only, &block)
|
def self.each(only, &block)
|
||||||
Dir["#{HOMEBREW_ALIASES}/*"].each do |path|
|
Dir["#{HOMEBREW_ALIASES}/*"].each do |path|
|
||||||
next if path.end_with? "~" # skip Emacs-like backup files
|
next if path.end_with? "~" # skip Emacs-like backup files
|
||||||
next if File.directory?(path)
|
next if File.directory?(path)
|
||||||
|
|
||||||
_shebang, _meta, *lines = File.readlines(path)
|
_shebang, meta, *lines = File.readlines(path)
|
||||||
target = File.basename(path)
|
name = T.must(meta)[/alias: brew (\S+)/, 1] || File.basename(path)
|
||||||
next if !only.empty? && only.exclude?(target)
|
next if !only.empty? && only.exclude?(name)
|
||||||
|
|
||||||
lines.reject! { |line| line.start_with?("#") || line =~ /^\s*$/ }
|
lines.reject! { |line| line.start_with?("#") || line =~ /^\s*$/ }
|
||||||
first_line = T.must(lines.first)
|
first_line = T.must(lines.first)
|
||||||
cmd = first_line.chomp
|
command = first_line.chomp
|
||||||
cmd.sub!(/ \$\*$/, "")
|
command.sub!(/ \$\*$/, "")
|
||||||
|
|
||||||
if cmd.start_with? "brew "
|
if command.start_with? "brew "
|
||||||
cmd.sub!(/^brew /, "")
|
command.sub!(/^brew /, "")
|
||||||
else
|
else
|
||||||
cmd = "!#{cmd}"
|
command = "!#{command}"
|
||||||
end
|
end
|
||||||
|
|
||||||
yield target, cmd if block.present?
|
yield name, command if block.present?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(aliases: String).void }
|
sig { params(aliases: String).void }
|
||||||
def self.show(*aliases)
|
def self.show(*aliases)
|
||||||
each([*aliases]) do |target, cmd|
|
each([*aliases]) do |name, command|
|
||||||
puts "brew alias #{target}='#{cmd}'"
|
puts "brew alias #{name}='#{command}'"
|
||||||
existing_alias = Alias.new(target, cmd)
|
existing_alias = Alias.new(name, command)
|
||||||
existing_alias.link unless existing_alias.symlink.exist?
|
existing_alias.link unless existing_alias.symlink.exist?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
#! /bin/bash
|
|
||||||
# alias: brew foo
|
|
||||||
#: * `foo` [args...]
|
|
||||||
#: `brew foo` is an alias for `brew bar`
|
|
||||||
brew bar $*
|
|
||||||
|
|
6
Library/Homebrew/test/.brew-aliases/foo_test
Executable file
6
Library/Homebrew/test/.brew-aliases/foo_test
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
# alias: brew foo-test
|
||||||
|
#: * `foo-test` [args...]
|
||||||
|
#: `brew foo-test` is an alias for `brew bar`
|
||||||
|
brew bar $*
|
||||||
|
|
@ -7,12 +7,12 @@ RSpec.describe Homebrew::Cmd::Alias do
|
|||||||
it_behaves_like "parseable arguments"
|
it_behaves_like "parseable arguments"
|
||||||
|
|
||||||
it "sets an alias", :integration_test do
|
it "sets an alias", :integration_test do
|
||||||
expect { brew "alias", "foo=bar" }
|
expect { brew "alias", "foo-test=bar" }
|
||||||
.to not_to_output.to_stdout
|
.to not_to_output.to_stdout
|
||||||
.and not_to_output.to_stderr
|
.and not_to_output.to_stderr
|
||||||
.and be_a_success
|
.and be_a_success
|
||||||
expect { brew "alias" }
|
expect { brew "alias" }
|
||||||
.to output(/brew alias foo='bar'/).to_stdout
|
.to output(/brew alias foo-test='bar'/).to_stdout
|
||||||
.and not_to_output.to_stderr
|
.and not_to_output.to_stderr
|
||||||
.and be_a_success
|
.and be_a_success
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user