From 7b09f956642c296203ad7a3bcc205de027105360 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Fri, 22 May 2009 16:21:10 +0100 Subject: [PATCH] Made brew ln more useful No need to specify exact versions or paths we try to be clever --- Cellar/homebrew/brew | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Cellar/homebrew/brew b/Cellar/homebrew/brew index aac8257087..b107b7b18d 100755 --- a/Cellar/homebrew/brew +++ b/Cellar/homebrew/brew @@ -45,13 +45,28 @@ case ARGV[0] puts "#{path} removed" when 'ln' then - abort "#{ARGV[1]} is not a directory" unless File.directory? ARGV[1] + target=Pathname.new(ARGV[1]) + target=$root+'Cellar'+target unless target.exist? + + abort "#{target} is not a directory" unless target.directory? + + target=target.realpath + + if target.parent.parent == $root + # we are one dir too high + kids=target.children + abort "#{target} is empty :(" if kids.length == 0 + abort "There are multiple versions of #{target.basename} installed please specify one" if kids.length > 1 + target=target.children.first + abort "#{target} is not a directory!" unless target.directory? + elsif target.parent.parent.parent != $root + abort '#{target} is not a keg' + end - #TODO if user specifies just name and not version dir, do latest version #TODO you should mkdirs as you find them and symlink files otherwise #TODO consider using hardlinks - target=Pathname.new(ARGV[1]).realpath + n=0 target.find do |from| next if from == ARGV[1] #rubysucks