-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
52 lines (46 loc) · 1.16 KB
/
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
46
47
48
49
50
51
52
def here(*paths)
File.expand_path(File.join(File.dirname(__FILE__), *paths))
end
def dotfiles
Dir[here('*')].map { |path| File.basename(path) }.reject { |path| path == "Rakefile" or path =~ /^README/ }
end
def run(cmd)
puts cmd
system cmd
end
task :default => :dotfiles
desc "Symlinks all my dotfiles"
task :dotfiles do
dotfiles.each do |dotfile|
link = File.expand_path("~/.#{dotfile}")
unless File.exists?(link)
run %Q{ln -s "#{here(dotfile)}" "#{link}"}
end
end
end
desc "Removes all my dotfile symlinks"
task :clean do
dotfiles.each do |dotfile|
link = File.expand_path("~/.#{dotfile}")
if File.symlink?(link)
run %Q{rm "#{link}"}
end
end
end
desc "Removes all existing symlinks, then re-symlinks my dotfiles"
task :reset do
dotfiles.each do |dotfile|
link = File.expand_path("~/.#{dotfile}")
if File.symlink?(link)
run %Q{rm "#{link}"}
end
end
puts "Existing symlinks have been removed."
dotfiles.each do |dotfile|
link = File.expand_path("~/.#{dotfile}")
unless File.exists?(link)
run %Q{ln -s "#{here(dotfile)}" "#{link}"}
end
end
puts "Dotfiles have been symlinked again."
end