From a681fda5cdca1c2a8bffad5687e71c9e9cf31c9f Mon Sep 17 00:00:00 2001 From: Alexander Kahn Date: Tue, 28 Dec 2010 16:52:10 -0500 Subject: [PATCH] Make symlinking actually work --- Rakefile | 42 ++++-------------------------------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/Rakefile b/Rakefile index ca3b293..dd4fd8b 100644 --- a/Rakefile +++ b/Rakefile @@ -6,51 +6,17 @@ desc 'Installs dotfiles from this distribution for the first time' task :setup do files = Dir.glob('*', File::FNM_DOTMATCH) - files = files - ['.', '..', '.git', 'Rakefile'] - - puts "Linking the following files:" + files = files - ['.', '..', '.git', 'Rakefile', '.Rakefile.swp'] files.map do |file| - puts file File.expand_path(file) end - files.each do |from| + from = File.expand_path(from) to = File.expand_path(File.join('~', File.basename(from))) - puts " - " + [from, to].join(' -> ') - if File.exists?(to) - print " ! Target exists... " - if File.symlink? to - FileUtils.rm to - puts "as a symlink, removed" - else - print "as a normal file/directory, moving to #{File.basename(to)}~... " - toto = to + '~' - - if File.exist? toto - print "already exists! r)emove, or s)kip? " - order = STDIN.gets.chomp - - case order - when 'r' - print ' ! Removing... ' - FileUtils.rm toto - when 's' - puts ' ! Okay, skipped ' - next - else - puts " ! Invalid entry, so skipping" - next - end - end - - FileUtils.mv to, toto - puts "Done!" - end - end - - FileUtils.symlink(from, to) + puts "* Linking #{from} to #{to}." + FileUtils.ln_sf(from, to) end end