diff options
Diffstat (limited to 'Library/Homebrew/cmd/unlinkapps.rb')
| -rw-r--r-- | Library/Homebrew/cmd/unlinkapps.rb | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/Library/Homebrew/cmd/unlinkapps.rb b/Library/Homebrew/cmd/unlinkapps.rb index 864e33b27..ef11db602 100644 --- a/Library/Homebrew/cmd/unlinkapps.rb +++ b/Library/Homebrew/cmd/unlinkapps.rb @@ -5,15 +5,11 @@ module Homebrew def unlinkapps 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 + return unless File.exist? target_dir - cellar_apps = Dir[target_dir + '/*.app'].select do |app| - if File.symlink?(app) && File.readlink(app).match(HOMEBREW_CELLAR) - File.readlink app + cellar_apps = Dir[target_dir + "/*.app"].select do |app| + if File.symlink?(app) + should_unlink? File.readlink(app) end end @@ -24,4 +20,14 @@ module Homebrew puts "Finished unlinking from #{target_dir}" if cellar_apps end + + private + + def should_unlink? file + 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 end |
