aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorAdam Vandenberg2013-09-17 06:55:13 -0700
committerAdam Vandenberg2013-09-17 06:55:13 -0700
commit907ac79606537189a0a7c822be1210c4d4801df3 (patch)
treed76ef4403ff76c9440b446ba4297f8422bb38791 /Library/Homebrew
parente8a892068ecfe853f2f363764f228b9335d9bcab (diff)
downloadbrew-907ac79606537189a0a7c822be1210c4d4801df3.tar.bz2
make linkapps official
Diffstat (limited to 'Library/Homebrew')
-rwxr-xr-xLibrary/Homebrew/cmd/linkapps.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/Library/Homebrew/cmd/linkapps.rb b/Library/Homebrew/cmd/linkapps.rb
new file mode 100755
index 000000000..5cf254625
--- /dev/null
+++ b/Library/Homebrew/cmd/linkapps.rb
@@ -0,0 +1,36 @@
+# Links any Applications (.app) found in installed prefixes to /Applications
+require 'keg'
+
+module Homebrew extend self
+
+ 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
+
+ HOMEBREW_CELLAR.subdirs.each do |rack|
+ kegs = rack.subdirs.map { |d| Keg.new(d) }
+ next if kegs.empty?
+
+ keg = kegs.detect(&:linked?) || kegs.max {|a,b| a.version <=> b.version}
+
+ Dir["#{keg}/*.app", "#{keg}/bin/*.app", "#{keg}/libexec/*.app"].each do |app|
+ puts "Linking #{app}"
+ app_name = File.basename(app)
+ target = "#{target_dir}/#{app_name}"
+
+ if File.exist?(target) && !File.symlink?(target)
+ onoe "#{target} already exists, skipping."
+ next
+ end
+ system "ln", "-sf", app, target_dir
+ end
+ end
+
+ puts "Finished linking. Find the links under #{target_dir}."
+ end
+end