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?
|
2015-10-20 07:16:18 +02:00
|
|
|
file.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_PREFIX}/opt/")
|
2014-12-18 15:13:04 +08:00
|
|
|
else
|
2015-10-20 07:16:18 +02:00
|
|
|
ARGV.kegs.any? { |keg| file.start_with?("#{keg}/", "#{keg.opt_record}/") }
|
2014-12-18 15:13:04 +08:00
|
|
|
end
|
|
|
|
end
|
2013-09-21 17:11:25 +02:00
|
|
|
end
|