brew/Library/Homebrew/cmd/linkapps.rb

42 lines
1.1 KiB
Ruby
Raw Normal View History

2013-09-17 06:55:13 -07:00
# Links any Applications (.app) found in installed prefixes to /Applications
require "keg"
require "formula"
2013-09-17 06:55:13 -07:00
module Homebrew
2013-09-17 06:55:13 -07:00
def linkapps
target_dir = ARGV.include?("--local") ? File.expand_path("~/Applications") : "/Applications"
unless File.exist? target_dir
opoo "#{target_dir} does not exist, stopping."
puts "Run `mkdir #{target_dir}` first."
exit 1
end
if ARGV.named.empty?
kegs = Formula.racks.map do |rack|
keg = rack.subdirs.map { |d| Keg.new(d) }
next if keg.empty?
keg.detect(&:linked?) || keg.max { |a, b| a.version <=> b.version }
end
else
kegs = ARGV.kegs
end
2013-09-17 06:55:13 -07:00
kegs.each do |keg|
keg = keg.opt_record if keg.optlinked?
2013-09-17 06:55:13 -07:00
Dir["#{keg}/*.app", "#{keg}/bin/*.app", "#{keg}/libexec/*.app"].each do |app|
puts "Linking #{app} to #{target_dir}."
2013-09-17 06:55:13 -07:00
app_name = File.basename(app)
target = "#{target_dir}/#{app_name}"
if File.exist?(target) && !File.symlink?(target)
onoe "#{target} already exists, skipping."
next
end
2013-09-17 06:55:13 -07:00
system "ln", "-sf", app, target_dir
end
end
end
end