Skip to content

Commit

Permalink
Merge pull request #58 from kabel/repair-aliases
Browse files Browse the repository at this point in the history
brew alias automatically re-symlinks missing aliases
  • Loading branch information
MikeMcQuaid authored Jan 26, 2024
2 parents 22813f2 + f2a82f9 commit a20493d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/aliases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def remove(name)
Alias.new(name).remove
end

def show(*aliases)
def each(only)
Dir["#{BASE_DIR}/*"].each do |path|
next if path.end_with? "~" # skip Emacs-like backup files

_, meta, *lines = File.readlines(path)
target = meta.chomp.delete_prefix("# alias: brew ")
next if !aliases.empty? && aliases.exclude?(target)
next if !only.empty? && only.exclude?(target)

lines.reject! { |line| line.start_with?("#") || line =~ /^\s*$/ }
cmd = lines.first.chomp
Expand All @@ -51,7 +51,15 @@ def show(*aliases)
cmd = "!#{cmd}"
end

yield target, cmd
end
end

def show(*aliases)
each(aliases) do |target, cmd|
puts "brew alias #{target}='#{cmd}'"
existing_alias = Alias.new(target, cmd)
existing_alias.write override: true unless existing_alias.symlink.exist?
end
end

Expand Down

0 comments on commit a20493d

Please sign in to comment.