Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (39 sloc) 963 Bytes
class Installer
def symlink(target, link)
if File.symlink?(link)
unlink(link)
elsif File.exist?(link)
puts "ERROR: File exists: #{link}"
exit 1
end
puts "Symlinking #{link} => #{target}"
File.symlink(target, link)
end
def delete_symlink(link)
unlink(link) if File.symlink?(link)
end
def unlink(link)
if File.exist?(link)
descriptor = File.symlink?(link) ? "symlink" : "file"
puts "Deleting #{descriptor} #{link}"
File.unlink(link)
end
end
end
def pwd; File.dirname(__FILE__); end
def target_path(file)
File.join(ENV["HOME"], ".#{file}")
end
files = File.new(File.join(pwd, "MANIFEST"), "r").read.split("\n")
desc "Install all dotfiles"
task :install do
files.each do |file|
Installer.new.symlink(File.join(pwd, file), target_path(file))
end
end
desc "Remove all dotfies"
task :uninstall do
files.each do |file|
Installer.new.unlink(target_path(file))
end
end