-
Notifications
You must be signed in to change notification settings - Fork 27
/
Rakefile
45 lines (39 loc) · 963 Bytes
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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