From d6b5f2185202016de23643762ceb727a89fe50ac Mon Sep 17 00:00:00 2001 From: Nick Nisi Date: Mon, 30 Apr 2012 22:26:42 -0500 Subject: [PATCH] Added restore and backup tasks to rakefile --- Rakefile | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Rakefile b/Rakefile index f744242..318fdca 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,33 @@ require 'rake' # loosely based on zholman's install script +def linkables + linkables = Dir.glob('**/*.symlink') + linkables.each do |linkable| + file = linkable.split('/').last.split('.symlink').last + target = "#{ENV["HOME"]}/.#{file}" + yield file, target if block_given? + end +end + +desc "make a backup of all files that will be replaced (if they exist)" +task :backup do + linkables do |file, target| + if File.exists?(target) || File.symlink?(target) + `mv "$HOME/.#{file}" "$HOME/.#{file}.backup"` + end + end +end + +desc "restore the backups" +task :restore do + linkables do |file, target| + if File.exists?("#{ENV['HOME']}/.#{file}.backup") + `mv "$HOME/.#{file}.backup" "$HOME/.#{file}"` + end + end +end + desc "create all the symlinks" task :install do linkables = Dir.glob('*/**{.symlink}') @@ -13,4 +40,15 @@ task :install do end end +desc "remove all files added" +task :uninstall do + Dir.glob('**/*.symlink').each do |linkable| + file = linkable.split('/').last.split('.symlink').last + target = "#{ENV["HOME"]}/.#{file}" + if File.symlink?(target) + FileUtils.rm(target) + end + end +end + task :default => 'install'