2013-09-21 17:11:25 +02:00
|
|
|
# Unlinks any Applications (.app) found in installed prefixes from /Applications
|
2015-08-03 13:09:07 +01:00
|
|
|
require "keg"
|
2013-09-21 17:11:25 +02:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2013-09-21 17:11:25 +02:00
|
|
|
def unlinkapps
|
|
|
|
target_dir = ARGV.include?("--local") ? File.expand_path("~/Applications") : "/Applications"
|
|
|
|
|
2014-12-18 15:13:04 +08:00
|
|
|
return unless File.exist? target_dir
|
2013-09-21 17:11:25 +02:00
|
|
|
|
2014-12-18 15:13:04 +08:00
|
|
|
cellar_apps = Dir[target_dir + "/*.app"].select do |app|
|
|
|
|
if File.symlink?(app)
|
|
|
|
should_unlink? File.readlink(app)
|
2013-09-21 17:11:25 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
cellar_apps.each do |app|
|
|
|
|
puts "Unlinking #{app}"
|
|
|
|
system "unlink", app
|
|
|
|
end
|
|
|
|
|
|
|
|
puts "Finished unlinking from #{target_dir}" if cellar_apps
|
|
|
|
end
|
2014-12-18 15:13:04 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def should_unlink?(file)
|
2014-12-18 15:13:04 +08:00
|
|
|
if ARGV.named.empty?
|
|
|
|
file.match(HOMEBREW_CELLAR) || file.match("#{HOMEBREW_PREFIX}/opt")
|
|
|
|
else
|
|
|
|
ARGV.kegs.any? { |keg| file.match(keg.to_s) || file.match(keg.opt_record.to_s) }
|
|
|
|
end
|
|
|
|
end
|
2013-09-21 17:11:25 +02:00
|
|
|
end
|